私はng2プロジェクトでサードパーティのモジュールを使用しています。このモジュールを模擬してテストすることができますが、モジュール自体は私のサービスに注入されません。非ng2モジュールを模擬する方法は?
このClient
を私のテストでは使用しないで上書きします実際のモジュールですか?
import {Injectable} from '@angular/core';
var Client = require('ssh2').Client;
@Injectable()
export class SshService {
constructor(){
//Should log "hello world"
Client.myFunc();
}
}
import { TestBed, inject } from '@angular/core/testing';
describe('My Service',() => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
SshService
]
});
});
it('should work as expected',
inject([SshService], (sshService:SshService) => {
sshService.Client = {
myFunc:function(){
console.log('hello world')
}
}
console.log(sshService.Client)
}));
});
どうしますか? –
@JustinYoung同じ考え、別の実装:http://stackoverflow.com/a/37176929/3033053 – silencedmessage