2024-03-06 02:24:20 +03:00
|
|
|
import { TSESLint } from '@typescript-eslint/utils';
|
|
|
|
|
|
|
|
import { rule, RULE_NAME } from './use-getLoadable-and-getValue-to-get-atoms';
|
|
|
|
|
|
|
|
const ruleTester = new TSESLint.RuleTester({
|
|
|
|
parser: require.resolve('@typescript-eslint/parser'),
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
ruleTester.run(RULE_NAME, rule, {
|
|
|
|
valid: [
|
|
|
|
{
|
|
|
|
code: 'const atoms = snapshot.getLoadable(someState).getValue();',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'const atoms = snapshot.getLoadable(someState(viewId)).getValue();',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
invalid: [
|
|
|
|
{
|
|
|
|
code: 'const atoms = await snapshot.getPromise(someState);',
|
|
|
|
errors: [
|
|
|
|
{
|
2024-03-09 12:48:19 +03:00
|
|
|
messageId: 'invalidAccessorOnSnapshot',
|
2024-03-06 02:24:20 +03:00
|
|
|
},
|
|
|
|
],
|
2024-03-09 12:48:19 +03:00
|
|
|
output: 'const atoms = await snapshot.getLoadable(someState);',
|
2024-03-06 02:24:20 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'const atoms = await snapshot.getPromise(someState(viewId));',
|
|
|
|
errors: [
|
|
|
|
{
|
2024-03-09 12:48:19 +03:00
|
|
|
messageId: 'invalidAccessorOnSnapshot',
|
2024-03-06 02:24:20 +03:00
|
|
|
},
|
|
|
|
],
|
2024-03-09 12:48:19 +03:00
|
|
|
output: 'const atoms = await snapshot.getLoadable(someState(viewId));',
|
2024-03-06 02:24:20 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'const atoms = snapshot.getLoadable(someState).anotherMethod();',
|
|
|
|
errors: [
|
|
|
|
{
|
|
|
|
messageId: 'invalidWayToGetAtoms',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
output: 'const atoms = snapshot.getLoadable(someState).getValue();',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|