-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from XbyOrange/v1.3.0
V1.3.0
- Loading branch information
Showing
10 changed files
with
306 additions
and
53 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,96 @@ | ||
const test = require("mocha-sinon-chai"); | ||
|
||
const { Origin, sources } = require("../src/Origin"); | ||
|
||
test.describe("Origin defaultValue as callback", () => { | ||
let sandbox; | ||
|
||
test.beforeEach(() => { | ||
sandbox = test.sinon.createSandbox(); | ||
}); | ||
|
||
test.afterEach(() => { | ||
sandbox.restore(); | ||
sources.clear(); | ||
}); | ||
|
||
test.describe("when Origin has defaultValue callback defined", () => { | ||
test.describe("read method", () => { | ||
test.describe("without query", () => { | ||
test.it( | ||
"should return the result of defaultValue callback until real value is returned", | ||
() => { | ||
const TestOrigin = class extends Origin { | ||
constructor(id, defaultValue, options) { | ||
const getDefaultValue = () => { | ||
return defaultValue + 2; | ||
}; | ||
super(id, getDefaultValue, options); | ||
} | ||
|
||
_read() { | ||
return Promise.resolve(5); | ||
} | ||
}; | ||
const testOrigin = new TestOrigin("", 4); | ||
test.expect(testOrigin.read.value).to.equal(6); | ||
return testOrigin.read().then(() => { | ||
return test.expect(testOrigin.read.value).to.equal(5); | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
test.describe("with query", () => { | ||
const QUERY = "foo-query"; | ||
const TestOrigin = class extends Origin { | ||
constructor(id, defaultValue, options) { | ||
const getDefaultValue = query => { | ||
return query; | ||
}; | ||
super(id, getDefaultValue, options); | ||
} | ||
|
||
_read() { | ||
return Promise.resolve("foo-result"); | ||
} | ||
}; | ||
|
||
test.describe("with simple query", () => { | ||
test.it( | ||
"should pass query to defaultValue callback, and return the result until real value is returned", | ||
() => { | ||
const testOrigin = new TestOrigin("", 4).query(QUERY); | ||
test.expect(testOrigin.read.value).to.equal("foo-query"); | ||
return testOrigin.read().then(() => { | ||
return test.expect(testOrigin.read.value).to.equal("foo-result"); | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
test.describe("with chained query", () => { | ||
test.it( | ||
"should pass chained query to defaultValue callback, and return the result until real value is returned", | ||
() => { | ||
const testOrigin = new TestOrigin("", 4) | ||
.query({ | ||
foo: "foo" | ||
}) | ||
.query({ | ||
foo2: "foo2" | ||
}); | ||
test.expect(testOrigin.read.value).to.deep.equal({ | ||
foo: "foo", | ||
foo2: "foo2" | ||
}); | ||
return testOrigin.read().then(() => { | ||
return test.expect(testOrigin.read.value).to.equal("foo-result"); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.