Skip to content

Instantly share code, notes, and snippets.

@carlosble
Created April 5, 2017 18:10
Show Gist options
  • Save carlosble/14a0068b9fe81c655992f6267c8b0a45 to your computer and use it in GitHub Desktop.
Save carlosble/14a0068b9fe81c655992f6267c8b0a45 to your computer and use it in GitHub Desktop.
Refactoring the test
it("saves the profile in the backend", (done) => {
simulateChangeInPhone(change);
let savedProfile = spyOnSaveProfile();
eventually(() => {
expect(savedProfile.phone).toEqual(change);
}, done);
saveProfileButton().simulate("click");
});
function spyOnSaveProfile(){
let actualProfile = {};
stubApi.saveProfile = (profile) => {
Object.assign(actualProfile, profile);
return Promise.resolve({message: 'Success'});
};
return actualProfile;
}
function eventually(expectation, done){
spyNotifier.slowOperationFinished = () => {
expectation();
done();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment