angular - Using Jasmine with Ionic is there a way to mock/stub a static namespace function call? -
i'm new space bear me. working in ionic 2 project using angular 2, typescript, , jasmine unit testing. i'm trying write unit test right weird case. have third-party library import in component import @ top import * thirdparty "thirdparty-library"
, later component makes call thirdparty.setup(somestuff, somemorestuff, anotherfunc)
.
really want have mock thirdparty
own fake anotherfunc
that pass unit test. there way pass in constructor , have override thirdparty
namespace? thank in advance
functions being first class citizens, can assigned new values. if want, can like
let ogfunct; beforeeach(() => { ogfunt = thirdparty.setup; thirdparty.setup = (arg1, arg2, arg3) => { console.log(`arg1 - arg2 - arg2`) } }); aftereach(() => { thirdparty.setup = ogfunct; });
sometimes library type definitions make function read-only. in case, can't assign anything. maybe in case better option abstract third-party calls service. , mock service. might consider doing anyway. think better design using third-party directly in component.
Comments
Post a Comment