From e3c047831a0edba9957a6482bd0cea228586dc09 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 13 Jan 2018 23:29:16 -0500 Subject: [PATCH] add test for #77 --- test/app/routes/api/delete/[id].js | 9 +++++++++ test/app/routes/delete-test.html | 15 +++++++++++++++ test/common/test.js | 13 +++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/app/routes/api/delete/[id].js create mode 100644 test/app/routes/delete-test.html diff --git a/test/app/routes/api/delete/[id].js b/test/app/routes/api/delete/[id].js new file mode 100644 index 0000000..28eb0d0 --- /dev/null +++ b/test/app/routes/api/delete/[id].js @@ -0,0 +1,9 @@ +export function del(req, res) { + res.set({ + 'Content-Type': 'application/json' + }); + + res.end(JSON.stringify({ + id: req.params.id + })); +} \ No newline at end of file diff --git a/test/app/routes/delete-test.html b/test/app/routes/delete-test.html new file mode 100644 index 0000000..d2df93c --- /dev/null +++ b/test/app/routes/delete-test.html @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/test/common/test.js b/test/common/test.js index 56e28f6..900628e 100644 --- a/test/common/test.js +++ b/test/common/test.js @@ -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', () => {