sinon#restore TypeScript Examples
The following examples show how to use
sinon#restore.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: logger-spec.ts From ui5-language-assistant with Apache License 2.0 | 5 votes |
describe("the Language Server Logger", () => {
let errorSpy;
beforeEach(() => {
errorSpy = spy(console, "error");
});
afterEach(() => {
restore();
});
it("supports structured JSON logging", async () => {
getLogger().error("hello world", { a: 1, b: [1, 2, 3] });
const logEntry = errorSpy.args[0];
const jsonLogEntry = JSON.parse(logEntry);
expect(jsonLogEntry).to.have.property("a", 1);
expect(jsonLogEntry).to.have.deep.property("b", [1, 2, 3]);
});
context("log level", () => {
let orgLevel: LogLevel;
beforeEach(() => {
orgLevel = getLogLevel();
});
it("supports changing the log level", async () => {
setLogLevel("fatal");
getLogger().error(
"`error` is lower than `fatal` so no logging should happen"
);
expect(errorSpy).to.have.not.been.called;
getLogger().fatal("`fatal` should cause logging to the console");
expect(errorSpy).to.have.been.called;
});
it("does not allow changing to an **unknown** logLevel", async () => {
// "Verbose" is not a valid log level for the language server
setLogLevel("Verbose" as "trace");
const currentLogLevel = getLogLevel();
expect(currentLogLevel).to.not.equal("Verbose");
expect(validLoggingLevelValues[currentLogLevel]).to.be.true;
});
afterEach(() => {
setLogLevel(orgLevel);
});
});
});
Example #2
Source File: testSetup.ts From ardrive-cli with GNU Affero General Public License v3.0 | 5 votes |
// Restores the default sandbox after every test
exports.mochaHooks = {
afterEach() {
restore();
}
};