diff --git a/index.js b/index.js index c5c3d87..4399473 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,10 @@ export default class GitHubProject { constructor(options) { const { owner, number, fields = {} } = options; + if (Number.isNaN(number)) { + throw new TypeError("The number option must be a valid number"); + } + // set octokit either from `options.octokit` or `options.token` const octokit = "token" in options diff --git a/test/constructor.test.js b/test/constructor.test.js index 6378b53..f340282 100644 --- a/test/constructor.test.js +++ b/test/constructor.test.js @@ -50,3 +50,15 @@ test("constructor with token", (t) => { t.true(project.octokit instanceof Octokit); }); + +test("rejects NaN as the number option", (t) => { + t.throws( + () => + new GitHubProject({ + owner: "owner", + number: NaN, + octokit: new Octokit(), + }), + { message: "The number option must be a valid number" }, + ); +});