-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9c6f83
commit 370a19d
Showing
8 changed files
with
4,024 additions
and
7,211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
{ | ||
"extends": "standard", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"browser": true, | ||
"mocha": true, | ||
"node": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": false, | ||
"trailingComma": "none" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,64 +1,60 @@ | ||
import { expect } from 'chai' | ||
import { expect, describe, it } from 'vitest' | ||
import { combineFilters } from '../src/index' | ||
|
||
runTestCombineFilters() | ||
|
||
function runTestCombineFilters () { | ||
describe('Combine Filters', () => { | ||
const sample = { | ||
action: { type: 'TEST' }, | ||
currentState: 1, | ||
previousHistory: [0, -1] | ||
} | ||
|
||
function checkArguments (action, currentState, previousHistory) { | ||
return ( | ||
action === sample.action && | ||
currentState === sample.currentState && | ||
previousHistory === sample.previousHistory | ||
) | ||
} | ||
|
||
function checkArgumentsNot (action, currentState, previousHistory) { | ||
return ( | ||
action !== sample.action || | ||
currentState !== sample.currentState || | ||
previousHistory !== sample.previousHistory | ||
) | ||
} | ||
|
||
function checkStateNot1 (action, state) { return state !== 1 } | ||
function checkStateNot2 (action, state) { return state !== 2 } | ||
|
||
function checkIfCalled (action) { | ||
action.hasBeenCalled = true | ||
return true | ||
} | ||
|
||
it('should pass its arguments while calling a filter', () => { | ||
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory)) | ||
.to.equal(true) | ||
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory)) | ||
.to.equal(false) | ||
}) | ||
describe('Combine Filters', () => { | ||
const sample = { | ||
action: { type: 'TEST' }, | ||
currentState: 1, | ||
previousHistory: [0, -1] | ||
} | ||
|
||
function checkArguments (action, currentState, previousHistory) { | ||
return ( | ||
action === sample.action && | ||
currentState === sample.currentState && | ||
previousHistory === sample.previousHistory | ||
) | ||
} | ||
|
||
function checkArgumentsNot (action, currentState, previousHistory) { | ||
return ( | ||
action !== sample.action || | ||
currentState !== sample.currentState || | ||
previousHistory !== sample.previousHistory | ||
) | ||
} | ||
|
||
function checkStateNot1 (action, state) { return state !== 1 } | ||
function checkStateNot2 (action, state) { return state !== 2 } | ||
|
||
function checkIfCalled (action) { | ||
action.hasBeenCalled = true | ||
return true | ||
} | ||
|
||
it('should pass its arguments while calling a filter', () => { | ||
expect(combineFilters(checkArguments, checkArguments)(sample.action, sample.currentState, sample.previousHistory)) | ||
.to.equal(true) | ||
expect(combineFilters(checkArgumentsNot, checkArguments)(sample.action, sample.currentState, sample.previousHistory)) | ||
.to.equal(false) | ||
}) | ||
|
||
it('should return false if any filter does', () => { | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false) | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false) | ||
}) | ||
it('should return false if any filter does', () => { | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 1)).to.equal(false) | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 2)).to.equal(false) | ||
}) | ||
|
||
it('should return true if every filter does', () => { | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true) | ||
}) | ||
it('should return true if every filter does', () => { | ||
expect(combineFilters(checkStateNot1, checkStateNot2)(null, 3)).to.equal(true) | ||
}) | ||
|
||
it('should not call remaining filters if one already returned false', () => { | ||
const act = { hasBeenCalled: false } | ||
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled) | ||
it('should not call remaining filters if one already returned false', () => { | ||
const act = { hasBeenCalled: false } | ||
const combined = combineFilters(checkStateNot1, checkStateNot2, checkIfCalled) | ||
|
||
combined(act, 2) | ||
expect(act.hasBeenCalled).to.equal(false) | ||
combined(act, 3) | ||
expect(act.hasBeenCalled).to.equal(true) | ||
}) | ||
combined(act, 2) | ||
expect(act.hasBeenCalled).to.equal(false) | ||
combined(act, 3) | ||
expect(act.hasBeenCalled).to.equal(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,17 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
coverage: { | ||
provider: 'istanbul', | ||
reporter: ['text', 'lcov'], | ||
} | ||
}, | ||
build: { | ||
lib: { | ||
entry: './src/index.js', | ||
name: 'ReduxUndo' | ||
} | ||
} | ||
}) |
Oops, something went wrong.