-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for array utils with jest
- Loading branch information
Showing
13 changed files
with
14,426 additions
and
7,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,6 @@ npm-debug.log | |
# Rust binaries | ||
/native/**/target | ||
/.cargo | ||
|
||
# Jest coverage | ||
/assets/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
js/vendor/* | ||
webpack.config.js | ||
jest.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export default { | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'js/**/*.{js,ts}', | ||
], | ||
coveragePathIgnorePatterns: [ | ||
'/node_modules/', | ||
'/.*\\.test\\.ts$', | ||
'.*\\.d\\.ts$', | ||
], | ||
coverageDirectory: '<rootDir>/coverage/', | ||
coverageThreshold: { | ||
global: { | ||
statements: 100, | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
}, | ||
}, | ||
preset: 'ts-jest/presets/js-with-ts-esm', | ||
testEnvironment: 'node', | ||
testPathIgnorePatterns: ['/node_modules/', '/dist/'], | ||
moduleNameMapper: { | ||
'./js/(.*)': '<rootDir>/js/$1', | ||
}, | ||
globals: { | ||
extensionsToTreatAsEsm: ['.ts', '.js'], | ||
'ts-jest': { | ||
useESM: true | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { moveElement } from '../array'; | ||
|
||
describe('moveElement', () => { | ||
describe('swap two items in a 2-item array', () => { | ||
it('should work with descending index parameters', () => { | ||
const input = [true, false]; | ||
moveElement(input, 1, 0); | ||
expect(input).toEqual([false, true]); | ||
}); | ||
|
||
it('should work with ascending index parameters', () => { | ||
const input = [true, false]; | ||
moveElement(input, 0, 1); | ||
expect(input).toEqual([false, true]); | ||
}); | ||
}); | ||
|
||
describe('swap first and last item in a 3-item array', () => { | ||
it('should work with descending index parameters', () => { | ||
const input = ['a', 'b', 'c']; | ||
moveElement(input, 2, 0); | ||
expect(input).toEqual(['c', 'a', 'b']); | ||
}); | ||
|
||
it('should work with ascending index parameters', () => { | ||
const input = ['a', 'b', 'c']; | ||
moveElement(input, 0, 2); | ||
expect(input).toEqual(['b', 'c', 'a']); | ||
}); | ||
}); | ||
|
||
describe('swap items in the middle of a 4-item array', () => { | ||
it('should work with descending index parameters', () => { | ||
const input = ['a', 'b', 'c', 'd']; | ||
moveElement(input, 2, 1); | ||
expect(input).toEqual(['a', 'c', 'b', 'd']); | ||
}); | ||
it('should work with ascending index parameters', () => { | ||
const input = ['a', 'b', 'c', 'd']; | ||
moveElement(input, 1, 2); | ||
expect(input).toEqual(['a', 'c', 'b', 'd']); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.