Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wimpert committed May 15, 2023
1 parent 4cd644e commit 136e629
Showing 1 changed file with 65 additions and 60 deletions.
125 changes: 65 additions & 60 deletions packages/eslint-plugin-qwik/qwik.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,86 +24,92 @@ const testConfig = {
};

const ruleTester = new RuleTester(testConfig as any);
test('use-method-usage', () => {
test.only('use-method-usage', () => {
ruleTester.run('my-rule', rules['use-method-usage'] as any, {
valid: [
`
export function useSession1() {
useContext();
}
export function useSession2() {
return useContext();
}
export function useSession3() {
return useContext().value;
}
`,
export function useSession1() {
useContext();
}
export function useSession2() {
return useContext();
}
export function useSession3() {
return useContext().value;
}
`,
`
export const useSession1 = () => {
useContext();
}
export const useSession1 = () => {
useContext();
}
export const useSession2 = () => {
return useContext();
}
export const useSession2 = () => {
return useContext();
}
export const useSession3 = () => useContext();
export const useSession3 = () => useContext();
export const useSession4 = () => useContext().value;
export const useSession4 = () => useContext().value;
export const useSession5 = () => useContext().value + 10;
export const useSession5 = () => useContext().value + 10;
`,
`,

`
export const useSession1 = () => {
useContext()?.value;
}
export const useSession1 = () => {
useContext()?.value;
}
export const useSession2 = () => {
return useContext()?.value;
}
export const useSession2 = () => {
return useContext()?.value;
}
export const useSession3 = () => useContext()?.value;
export const useSession3 = () => useContext()?.value;
export const useSession4 = () => useContext()?.value;
export const useSession4 = () => useContext()?.value;
export const useSession5 = () => useContext()?.value; + 10;
export const useSession5 = () => useContext()?.value; + 10;
`,
`
export const HelloWorld = component$(async () => {
const [todoForm, { Form, Field, FieldArray }] = useForm<TodoForm>({
loader: useFormLoader(),
action: useFormAction(),
validate: zodForm$(todoSchema),
});
`,
`export const HelloWorld = component$(async () => {
const [todoForm, { Form, Field, FieldArray }] = useForm<TodoForm>({
loader: useFormLoader(),
action: useFormAction(),
validate: zodForm$(todoSchema),
});
});
`,
`
export const HelloWorld = component$(async () => {
useMethod();
await something();
let a;
a = 2;
return $(() => {
return <div>{a}</div>
});
});
const A = () => { console.log('A') };
export const B = () => {
A();
}
`,
`
export const HelloWorld = component$(async () => {
useMethod();
await something();
let a;
a = 2;
return $(() => {
return <div>{a}</div>
});
});
const A = () => { console.log('A') };
export const B = () => {
A();
}
`,
`export const HelloWorld = component$(async () => {
useMethod();
await something();
await stuff();
return $(() => {
return <div></div>
useMethod();
await something();
await stuff();
return $(() => {
return <div></div>
});
});`,

`export const HelloWorld = component$(async () => {
const test = useFunction() as string;
});
});`,
`,
],
invalid: [
{
Expand Down Expand Up @@ -136,7 +142,6 @@ export const HelloWorld = component$(async () => {
});`,
errors: [{ messageId: 'use-after-await' }],
},

{
code: `export function noUseSession() {
useContext();
Expand Down

0 comments on commit 136e629

Please sign in to comment.