-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for validateLanguageRequested
function
- Loading branch information
1 parent
f234aa7
commit 148d815
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const supportedLanguages = require('../SUPPORTED-LANGUAGES.json'); | ||
const { getSupportedLanguagesWithNames } = require("./formatSupportedLanguages"); | ||
const { | ||
validateLanguageRequested, | ||
} = require("./validateLanguageRequested"); | ||
|
||
describe("validateLanguageRequested", () => { | ||
it("should return true if the requested language is supported", () => { | ||
const requestedLanguage = "en"; | ||
|
||
const result = validateLanguageRequested(requestedLanguage); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it("should throw an error if no language is provided", () => { | ||
const requestedLanguage = ""; | ||
const error = new Error("No language provided"); | ||
|
||
expect(() => { | ||
validateLanguageRequested(requestedLanguage); | ||
}).toThrowError(`${error.message}.\n\nPlease use one of these:\n\n${getSupportedLanguagesWithNames(supportedLanguages).join('\n')}`); | ||
}); | ||
|
||
it("should throw an error if the requested language is not supported", () => { | ||
const requestedLanguage = "invalid-language"; | ||
const error = new Error(`Language ${requestedLanguage} is not supported`); | ||
|
||
expect(() => { | ||
validateLanguageRequested(requestedLanguage); | ||
}).toThrowError(`${error.message}.\n\nPlease use one of these:\n\n${getSupportedLanguagesWithNames(supportedLanguages).join('\n')}`); | ||
}); | ||
|
||
it("should throw an error if the requested language is not supported by any engine", () => { | ||
const requestedLanguage = "ab"; | ||
const error = new Error(`Language ${requestedLanguage} is not supported by any engine`); | ||
|
||
expect(() => { | ||
validateLanguageRequested(requestedLanguage); | ||
}).toThrowError(`${error.message}.\n\nPlease use one of these:\n\n${getSupportedLanguagesWithNames(supportedLanguages).join('\n')}`); | ||
}); | ||
}); |