Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add scenarios for no-side-effects-wait-for
  • Loading branch information
renatoagds committed Jun 30, 2020
commit b2f1990688b73d9d583c32b33ca25c82f987bbdf
173 changes: 173 additions & 0 deletions tests/lib/rules/no-side-effects-wait-for.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { createRuleTester } from '../test-utils';
import rule, { RULE_NAME } from '../../../lib/rules/no-side-effects-wait-for';

const ruleTester = createRuleTester({
ecmaFeatures: {
jsx: true,
},
});

ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: `
await waitFor(() => expect(a).toEqual('a'))
`,
},
{
code: `
await waitFor(function() {
expect(a).toEqual('a')
})
`,
},
{
code: `
await waitFor(() => {
console.log('testing-library')
expect(b).toEqual('b')
})
`,
},
{
code: `
await waitFor(function() {
console.log('testing-library')
expect(b).toEqual('b')
})
`,
},
{
code: `
await waitFor(() => {})
`,
},
{
code: `
await waitFor(function() {})
`,
},
{
code: `
await waitFor(() => {
// testing
})
`,
},
{
code: `
await waitFor(function() {
// testing
})
`,
}
],
invalid: [
// fireEvent
{
code: `
await waitFor(() => {
fireEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(() => {
expect(b).toEqual('b')
fireEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(() => {
fireEvent.keyDown(input, {key: 'ArrowDown'})
expect(b).toEqual('b')
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
fireEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
expect(b).toEqual('b')
fireEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
fireEvent.keyDown(input, {key: 'ArrowDown'})
expect(b).toEqual('b')
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
// userEvent
{
code: `
await waitFor(() => {
userEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(() => {
expect(b).toEqual('b')
userEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(() => {
userEvent.keyDown(input, {key: 'ArrowDown'})
expect(b).toEqual('b')
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
userEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
expect(b).toEqual('b')
userEvent.keyDown(input, {key: 'ArrowDown'})
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
},
{
code: `
await waitFor(function() {
userEvent.keyDown(input, {key: 'ArrowDown'})
expect(b).toEqual('b')
})
`,
errors: [{ messageId: 'noSideEffectsWaitFor' }]
}
]
})