-
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.
test(logger): fixed test for logger to use rc5 features + updated kar…
…ma.conf/shim
- Loading branch information
1 parent
f335cc2
commit 837e9c4
Showing
3 changed files
with
126 additions
and
57 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// reference: https://github.com/ocombe/ng2-translate/blob/master/karma-test-shim.js | ||
|
||
// Turn on full stack traces in errors to help debugging | ||
Error.stackTraceLimit = Infinity; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
|
||
// Cancel Karma"s synchronous start, | ||
// we will call `__karma__.start()` later, once all the specs are loaded. | ||
__karma__.loaded = function () { }; | ||
|
||
System.config({ | ||
baseURL: "/base/", | ||
defaultJSExtensions: true, | ||
paths: { | ||
"n:*": "node_modules/*" | ||
}, | ||
map: { | ||
"@angular": "n:@angular", | ||
"@ssv": "n:@ssv", | ||
"rxjs": "n:rxjs", | ||
}, | ||
packages: { | ||
"@angular/common": { main: "index.js", defaultExtension: "js" }, | ||
"@angular/compiler": { main: "index.js", defaultExtension: "js" }, | ||
"@angular/core": { main: "index.js", defaultExtension: "js" }, | ||
"@angular/platform-browser": { main: "index.js", defaultExtension: "js" }, | ||
"@angular/platform-browser-dynamic": { main: "index.js", defaultExtension: "js" }, | ||
|
||
"@ssv/ng2-core": { main: "dist/amd/index.js", defaultExtension: "js" }, | ||
} | ||
}); | ||
|
||
System.import("@angular/platform-browser/src/browser/browser_adapter") | ||
.then(function (browser_adapter) { | ||
browser_adapter.BrowserDomAdapter.makeCurrent(); | ||
}) | ||
.then(function () { | ||
return Promise.all([ | ||
System.import("@angular/core/testing"), | ||
System.import("@angular/platform-browser-dynamic/testing") | ||
]).then(function (providers) { | ||
var testing = providers[0]; | ||
var testingBrowser = providers[1]; | ||
|
||
testing.TestBed.initTestEnvironment( | ||
testingBrowser.BrowserDynamicTestingModule, | ||
testingBrowser.platformBrowserDynamicTesting() | ||
); | ||
}); | ||
}) | ||
.then(function () { | ||
return Promise.all(resolveTestFiles()); | ||
}) | ||
.then(function () { | ||
__karma__.start(); | ||
}, function (error) { | ||
__karma__.error(error.stack || error); | ||
}); | ||
|
||
function onlySpecFiles(path) { | ||
return /[\.|_]spec\.js$/.test(path); | ||
} | ||
function resolveTestFiles() { | ||
return Object.keys(window.__karma__.files) // All files served by Karma. | ||
.filter(onlySpecFiles) | ||
.map(function (moduleName) { | ||
return System.import(moduleName); | ||
}); | ||
} |
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,22 +1,30 @@ | ||
import { | ||
it, | ||
inject, | ||
describe, | ||
expect, | ||
beforeEach, | ||
beforeEachProviders | ||
} from "@angular/core/testing"; | ||
import {inject, TestBed} from "@angular/core/testing"; | ||
|
||
import {LoggerService} from "./logger.service"; | ||
|
||
describe("LoggerService", () => { | ||
beforeEachProviders(() => [LoggerService]); | ||
|
||
let SUT: LoggerService; | ||
|
||
beforeEach(() => { | ||
spyOn(console, "log"); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [LoggerService] | ||
}); | ||
}); | ||
|
||
it("should log successfully", inject([LoggerService], (logger: LoggerService) => { | ||
beforeEach(inject([ | ||
LoggerService | ||
], ( | ||
logger: LoggerService | ||
) => { | ||
SUT = logger; | ||
spyOn(console, "log"); | ||
})); | ||
|
||
it("should log successfully", () => { | ||
let message = "Hello"; | ||
logger.log("log", message); | ||
SUT.log("log", message); | ||
expect(console.log).toHaveBeenCalledWith(message); | ||
})); | ||
}); | ||
}); |