Major refactoring using ESLint with rules from AirBnb and Vue. Enable most of the ESLint rules and do necessary linting in the code. Also add more information for rules that are disabled to describe what they are and why they are disabled. Allow logging (`console.log`) in test files, and in development mode (e.g. when working with `npm run serve`), but disable it when environment is production (as pre-configured by Vue). Also add flag (`--mode production`) in `lint:eslint` command so production linting is executed earlier in lifecycle. Disable rules that requires a separate work. Such as ESLint rules that are broken in TypeScript: no-useless-constructor (eslint/eslint#14118) and no-shadow (eslint/eslint#13014).
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import 'mocha';
|
|
import { expect } from 'chai';
|
|
import { scrambledEqual, sequenceEqual } from '@/application/Common/Array';
|
|
import { ComparerTestScenario } from './Array.ComparerTestScenario';
|
|
|
|
describe('Array', () => {
|
|
describe('scrambledEqual', () => {
|
|
describe('throws if arguments are undefined', () => {
|
|
it('first argument is undefined', () => {
|
|
const expectedError = 'undefined first array';
|
|
const act = () => scrambledEqual(undefined, []);
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
it('second arguments is undefined', () => {
|
|
const expectedError = 'undefined second array';
|
|
const act = () => scrambledEqual([], undefined);
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('returns as expected', () => {
|
|
// arrange
|
|
const scenario = new ComparerTestScenario()
|
|
.addSameItemsWithSameOrder(true)
|
|
.addSameItemsWithDifferentOrder(true)
|
|
.addDifferentItemsWithSameLength(false)
|
|
.addDifferentItemsWithDifferentLength(false);
|
|
// act
|
|
scenario.forEachCase((testCase) => {
|
|
it(testCase.name, () => {
|
|
const actual = scrambledEqual(testCase.first, testCase.second);
|
|
// assert
|
|
expect(actual).to.equal(testCase.expected);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
describe('sequenceEqual', () => {
|
|
describe('throws if arguments are undefined', () => {
|
|
it('first argument is undefined', () => {
|
|
const expectedError = 'undefined first array';
|
|
const act = () => sequenceEqual(undefined, []);
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
it('second arguments is undefined', () => {
|
|
const expectedError = 'undefined second array';
|
|
const act = () => sequenceEqual([], undefined);
|
|
expect(act).to.throw(expectedError);
|
|
});
|
|
});
|
|
describe('returns as expected', () => {
|
|
// arrange
|
|
const scenario = new ComparerTestScenario()
|
|
.addSameItemsWithSameOrder(true)
|
|
.addSameItemsWithDifferentOrder(true)
|
|
.addDifferentItemsWithSameLength(false)
|
|
.addDifferentItemsWithDifferentLength(false);
|
|
// act
|
|
scenario.forEachCase((testCase) => {
|
|
it(testCase.name, () => {
|
|
const actual = scrambledEqual(testCase.first, testCase.second);
|
|
// assert
|
|
expect(actual).to.equal(testCase.expected);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|