I have following file with class Project
// project.js
export default class Project {
static get name() {
return "some name"
}
}
And test when I want to mock name get method. I was trying two ways
import {Project, __RewireAPI__ as ProjectRewireAPI} from ".project"
...
class MockProject {
static get currentSlideId() {
return "SlideId";
}
}
ProjectRewireAPI.__Rewire__('Project', MockProject);
console.log("Mock project", Project); // undefined
...
and doesn't override the class globally.
Second idea
import Project from ".Project";
import sinon from "sinon";
...
var MockProject = sinon.stub();
MockProject.prototype.name = sinon.stub();
sinon.stub(MockProject, 'name', {get: () => { return "new name"}});
ProjectRewireAPI.__Rewire__('Project', MockProject);
...
but it throws
Attempted to wrap undefined property name as function
wrapMethod@/node_modules/sinon/lib/sinon/util/core.js:106:0
I don't know how to do it properly and asking for your help.
Aucun commentaire:
Enregistrer un commentaire