Skip to content

Commit fd83bcb

Browse files
author
Joao
committed
Test: Add controller code for valid/invalid cases
These code snippets provide a more concrete context of the rule’s usage in an Ember app
1 parent ad3279b commit fd83bcb

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/lib/rules/no-const-outside-module-scope.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ var ruleTester = new RuleTester({
2222
ruleTester.run('no-const-outside-module-scope', rule, {
2323
valid: [
2424
'const FOOBAR = 5;',
25-
'export const FOOBAR = 5;'
25+
'export const FOOBAR = 5;',
26+
`
27+
import Controller from '@ember/controller';
28+
const COUNT = 5;
29+
export default class extends Controller {
30+
get count() {
31+
let listCount = this.module.scope ? this.list.length : COUNT;
32+
return listCount;
33+
}
34+
}
35+
`
2636
],
2737

2838
invalid: [{
@@ -33,5 +43,25 @@ ruleTester.run('no-const-outside-module-scope', rule, {
3343
code: 'function foobar() { const FOOBAR = 5; return FOOBAR; }',
3444
output: 'function foobar() { let FOOBAR = 5; return FOOBAR; }',
3545
errors: [{ message: '`const` should only be used in module scope (not inside functions/blocks).' }]
46+
}, {
47+
code: `
48+
import Controller from '@ember/controller';
49+
export default class extends Controller {
50+
get isControllerScope() {
51+
const { scope } = this
52+
return Boolean(scope)
53+
}
54+
}
55+
`,
56+
output: `
57+
import Controller from '@ember/controller';
58+
export default class extends Controller {
59+
get isControllerScope() {
60+
let { scope } = this
61+
return Boolean(scope)
62+
}
63+
}
64+
`,
65+
errors: [{ message: '`const` should only be used in module scope (not inside functions/blocks).' }]
3666
}]
3767
});

0 commit comments

Comments
 (0)