我在测试 ActivatedRoute queryParams 订阅中的逻辑时遇到问题。
constructor(private router: Router, private route: ActivatedRoute, private auth: AuthService) {}
ngOnInit(): void {
this.route.queryParams.subscribe((params:any) => {
if(params['data']) {
this.handle(params['data']);
} else {
if (this.auth.isAuthenticated()) {
this.router.navigate(['/home']);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
我想测试:
this.handle()模拟时触发params['data']this.auth.isAuthenticated()回报true是this.router.navigate被称为我已经尝试了很多东西,但我的想法已经用完了。
我的测试文件:
describe('TestComponent', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
const mockService = {
navigate: jasmine.createSpy('navigate'),
isAuthenticated: jasmine.createSpy('isAuthenticated'),
queryParams: jasmine.createSpy('queryParams')
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
providers: [
{ provide: Router, …Run Code Online (Sandbox Code Playgroud) 我通过brew安装纱线到我的macOS 10.13,纱线工作得很好.当我尝试使用npm时出现问题.我尝试运行的每个命令都出现以下错误:
gregor-mbp:~ gregor$ npm -v
module.js:471
throw err;
^
Error: Cannot find module 'number-is-nan'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/node_modules/code-point-at/index.js:2:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
Run Code Online (Sandbox Code Playgroud)
我试图将这个数字 - 纳米模块安装为全球纱线,但没有成功.
现在我必须安装所有软件包并在yarn上运行脚本,这不错,但我的项目有脚本通过npm运行其他脚本:
package.json示例:
...
"scripts": {
"start": "start-command",
"build": "build-command",
"development": "NODE_ENV=dev npm run build && npm run start",
"production": "NODE_ENV=prod npm run build && npm run start"
},
...
Run Code Online (Sandbox Code Playgroud)
当我运行时,yarn development …