-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
ESLintUsedPractice.spec.ts
49 lines (39 loc) · 1.96 KB
/
ESLintUsedPractice.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ESLintUsedPractice } from './ESLintUsedPractice';
import { ProgrammingLanguage } from '../../model';
import { PracticeEvaluationResult } from '../../model';
import { TestContainerContext, createTestContainer } from '../../inversify.config';
import { IPackageInspector } from '../../inspectors/IPackageInspector';
describe('ESLintUsedPractice', () => {
let practice: ESLintUsedPractice;
let containerCtx: TestContainerContext;
let packageInspector: IPackageInspector;
beforeAll(() => {
containerCtx = createTestContainer();
containerCtx.container.bind('ESLintUsedPractice').to(ESLintUsedPractice);
practice = containerCtx.container.get('ESLintUsedPractice');
packageInspector = <IPackageInspector>containerCtx.practiceContext.packageInspector;
});
it('Returns true if lang is a JavaScript or TypeScript', async () => {
const result = await practice.isApplicable(containerCtx.practiceContext);
expect(result).toEqual(true);
});
it('Returns false if lang is NOT a JavaScript or TypeScript', async () => {
containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.UNKNOWN;
const result = await practice.isApplicable(containerCtx.practiceContext);
expect(result).toEqual(false);
});
it('Detects ESLint', async () => {
packageInspector.hasPackage = () => true;
const result = await practice.evaluate(containerCtx.practiceContext);
expect(result).toEqual(PracticeEvaluationResult.practicing);
});
it('Did not detect ESLint', async () => {
packageInspector.hasPackage = () => false;
const result = await practice.evaluate(containerCtx.practiceContext);
expect(result).toEqual(PracticeEvaluationResult.notPracticing);
});
it('Did not detect ESLint and did not recognize packageInspector', async () => {
const result = await practice.evaluate({ ...containerCtx.practiceContext, packageInspector: undefined });
expect(result).toEqual(PracticeEvaluationResult.unknown);
});
});