add test for #77

This commit is contained in:
Rich Harris
2018-01-13 23:29:16 -05:00
parent 81b5e0d764
commit e3c047831a
3 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
export function del(req, res) {
res.set({
'Content-Type': 'application/json'
});
res.end(JSON.stringify({
id: req.params.id
}));
}

View File

@@ -0,0 +1,15 @@
<button class='del' on:click='del()'>delete</button>
<script>
export default {
methods: {
del() {
fetch(`/api/delete/42`, { method: 'DELETE' })
.then(r => r.json())
.then(data => {
window.deleted = data;
});
}
}
};
</script>

View File

@@ -289,6 +289,19 @@ function run(env) {
assert.equal(html, `URL is /show-url`);
});
it('calls a delete handler', async () => {
await nightmare
.goto(`${base}/delete-test`)
.wait(() => window.READY)
.click('.del')
.wait(() => window.deleted);
assert.equal(
await nightmare.evaluate(() => window.deleted.id),
42
);
});
});
describe('headers', () => {