Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active April 24, 2018 08:23
Show Gist options
  • Save jasonmit/52bd55ef3c1f1628405d809266fb125a to your computer and use it in GitHub Desktop.
Save jasonmit/52bd55ef3c1f1628405d809266fb125a to your computer and use it in GitHub Desktop.
spy
let updatedName = false;
let newName = 'Tom';
const spy = new Spy('test-create-user-form');
/* TODO: ability to override auth header when recording. use case: test account to read from api */
await visit('/signup');
except(signup.name.value).to.equal('Yehuda');
await signup.name.value(newName);
/* TODO: expose an API for grepping requests that have happened? */
/* reason being we need to ID of the user response to stub out the form post below */
const res = await spy.find('POST', '/api/user')[0];
/* intercept here so that your tests are not updating the db? */
server.patch(`/api/user/${res.json.id}`, (status, body) => {
updatedName = body.name === newName;
/* stop here or continue testing story for spyjs? */
/* take the form body, update name and return it back? */
return [200, assign({ name: 'Tom'}, body)];
});
await signup.submit();
expect(currentURL).to.equal('/welcome');
except(welcome.name.value).to.equal('Tom');
expect(updatedName).to.equal(true);
await spy.terminate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment