|
| 1 | +import {lint, ruleType, minItems} from '../../../src/rules/valid-values-type'; |
| 2 | +import {Severity} from '../../../src/types/severity'; |
| 3 | + |
| 4 | +describe('valid-values-type Unit Tests', () => { |
| 5 | + describe('a rule type value should be exported', () => { |
| 6 | + test('it should equal "array"', () => { |
| 7 | + expect(ruleType).toStrictEqual('array'); |
| 8 | + }); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('a minItems value should be exported', () => { |
| 12 | + test('it should equal 1', () => { |
| 13 | + expect(minItems).toStrictEqual(1); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('when package.json has node with incorrect format', () => { |
| 18 | + test('LintIssue object should be returned', () => { |
| 19 | + const packageJsonData = { |
| 20 | + type: 'type', |
| 21 | + }; |
| 22 | + const validValues = ['commonjs', 'module']; |
| 23 | + const response = lint(packageJsonData, Severity.Error, validValues); |
| 24 | + |
| 25 | + expect(response.lintId).toStrictEqual('valid-values-type'); |
| 26 | + expect(response.severity).toStrictEqual('error'); |
| 27 | + expect(response.node).toStrictEqual('type'); |
| 28 | + expect(response.lintMessage).toStrictEqual( |
| 29 | + 'Invalid value for type. Current value is type. Valid values include: commonjs, module.' |
| 30 | + ); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('when package.json has node with correct format', () => { |
| 35 | + test('LintIssue object should be returned', () => { |
| 36 | + const packageJsonData = { |
| 37 | + type: 'module', |
| 38 | + }; |
| 39 | + const validValues = ['commonjs', 'module']; |
| 40 | + const response = lint(packageJsonData, Severity.Error, validValues); |
| 41 | + |
| 42 | + expect(response).toBeNull(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('when package.json does not have node', () => { |
| 47 | + test('true should be returned', () => { |
| 48 | + const packageJsonData = {}; |
| 49 | + const response = lint(packageJsonData, Severity.Error, []); |
| 50 | + |
| 51 | + expect(response).toBeNull(); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments