File
Blob: samples/unit-tests/worker.js
| 1 | // Copyright (c) 2023 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | // Exporting a test is like exporting a `fetch()` handler. |
| 6 | // |
| 7 | // It's common to want to write multiple tests in one file. We can export each |
| 8 | // test under a different name. (BTW you can also export multiple `fetch()` |
| 9 | // handlers this way! But that's less commonly-used.) |
| 10 | |
| 11 | export let testStrings = { |
| 12 | async test(ctrl, env, ctx) { |
| 13 | if ("foo" + "bar" != "foobar") { |
| 14 | throw new Error("strings are broken!"); |
| 15 | } |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | export let testMath = { |
| 20 | async test(ctrl, env, ctx) { |
| 21 | if (1 + 1 != 2) { |
| 22 | throw new Error("math is broken!"); |
| 23 | } |
| 24 | } |
| 25 | }; |