diff options
author | 2024-02-19 18:36:53 +0900 | |
---|---|---|
committer | 2024-02-19 09:36:53 +0000 | |
commit | 43f87467c6aa060ccd44dc32b2f44461214c7026 (patch) | |
tree | f84aef24a34ef821759abc73bdcbf495101006bb | |
parent | 0c2ab5b155eb20f08772bc10b1db2409ce5bf04e (diff) | |
download | astro-43f87467c6aa060ccd44dc32b2f44461214c7026.tar.gz astro-43f87467c6aa060ccd44dc32b2f44461214c7026.tar.zst astro-43f87467c6aa060ccd44dc32b2f44461214c7026.zip |
Implement test using using assert.fail and assert to check ENOENT. (#10156)
-rw-r--r-- | packages/astro/test/i18n-routing.test.js | 90 |
1 files changed, 40 insertions, 50 deletions
diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index f8477a14e..3c9a19df6 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -576,22 +576,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -640,22 +638,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -684,11 +680,10 @@ describe('[SSG] i18n routing', () => { it('should return 404 when route contains the default locale', async () => { try { await fixture.readFile('/start/en/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); @@ -715,22 +710,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); }); @@ -810,22 +803,20 @@ describe('[SSG] i18n routing', () => { it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => { try { await fixture.readFile('/it/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); @@ -932,11 +923,10 @@ describe('[SSG] i18n routing', () => { it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => { try { await fixture.readFile('/fr/start/index.html'); - // failed - return false; - } catch { - // success - return true; + // It should throw before reaching this point + assert.fail('The file should not exist'); + } catch (e) { + assert.equal(e.message.includes('ENOENT'), true); } }); |