Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create max-nested-describe rule #845

Merged
merged 14 commits into from
Jul 21, 2021
Prev Previous commit
test: add cases for 5 max
  • Loading branch information
dominictwlee committed Jul 4, 2021
commit d5bb697ff49a932c4191c8f1af5cb48f48ade369
86 changes: 56 additions & 30 deletions src/rules/__tests__/max-nested-describe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,39 @@ const ruleTester = new TSESLint.RuleTester({
ruleTester.run('max-nested-describe', rule, {
G-Rath marked this conversation as resolved.
Show resolved Hide resolved
valid: [
dedent`
describe('foo', () => {
describe('bar', () => {
it('hello', async () => {
expect('hello').toBe('hello');
});
});
describe('foo', function() {
describe('bar', function () {
describe('baz', function () {
describe('qux', function () {
describe('qux', function () {
it('should get something', () => {
expect(getSomething()).toBe('Something');
});
})
})
})
})
});
`,
dedent`
describe('foo', () => {
describe('bar', () => {
it('hello', async () => {
expect('hello').toBe('hello');
});
});
describe('foo', function() {
describe('bar', function () {
describe('baz', function () {
describe('qux', function () {
describe('qux', function () {
it('should get something', () => {
expect(getSomething()).toBe('Something');
});
});

fdescribe('qux', () => {
it('something', async () => {
expect('something').toBe('something');
});
});
fdescribe('qux', () => {
it('something', async () => {
expect('something').toBe('something');
});
});
})
})
})
});
`,
dedent`
Expand Down Expand Up @@ -96,26 +108,39 @@ ruleTester.run('max-nested-describe', rule, {
describe('bar', function () {
describe('baz', function () {
describe('qux', function () {
it('should get something', () => {
expect(getSomething()).toBe('Something');
describe('quxx', function () {
describe('over limit', function () {
it('should get something', () => {
expect(getSomething()).toBe('Something');
});
});
});
})
})
})
});
});
});
});
`,
errors: [
{ messageId: 'exceededMaxDepth', line: 3, column: 5 },
{ messageId: 'exceededMaxDepth', line: 4, column: 7 },
],
errors: [{ messageId: 'exceededMaxDepth', line: 6, column: 11 }],
},
{
code: dedent`
describe('foo', () => {
describe('bar', () => {
describe('baz', () => {
it('should get something', () => {
expect(getSomething()).toBe('Something');
describe('baz1', () => {
describe('baz2', () => {
describe('baz3', () => {
it('should get something', () => {
expect(getSomething()).toBe('Something');
});
});

describe('baz4', () => {
it('should get something', () => {
expect(getSomething()).toBe('Something');
});
});
});
});
});

Expand All @@ -128,8 +153,8 @@ ruleTester.run('max-nested-describe', rule, {
});
`,
errors: [
{ messageId: 'exceededMaxDepth', line: 3, column: 5 },
{ messageId: 'exceededMaxDepth', line: 9, column: 5 },
{ messageId: 'exceededMaxDepth', line: 6, column: 11 },
{ messageId: 'exceededMaxDepth', line: 12, column: 11 },
],
},
{
Expand All @@ -156,6 +181,7 @@ ruleTester.run('max-nested-describe', rule, {
});
});
`,
options: [{ max: 2 }],
errors: [
{ messageId: 'exceededMaxDepth', line: 3, column: 5 },
{ messageId: 'exceededMaxDepth', line: 9, column: 5 },
Expand Down