Skip to content

Commit da5b791

Browse files
wincentbrianchandotcom
authored andcommitted
LPS-101640 Tweak tests
- Correct a bad description (says "doesn't throw" but supposed to be "throws"). - Replace the sample "broken input" with something that describes why it is broken (eg. "not a relative or absolute URL"). - Hard-code "http://localhost/" to explicitly confirm the invariant that `location.href` is always going to be a URL that ends with a trailing slash. - Add a blank line for consistency with style used elsewhere. At some point, this kind of thing will be autoformatted; see: https://github.com/liferay/eslint-config-liferay/issues/160
1 parent 2a8b6d8 commit da5b791

File tree

1 file changed

+10
-6
lines changed
  • modules/apps/frontend-js/frontend-js-web/test/liferay/util

1 file changed

+10
-6
lines changed

modules/apps/frontend-js/frontend-js-web/test/liferay/util/add_params.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,24 @@ describe('Liferay.Util.addParams', () => {
7070
expect(() => addParams(['one', 'two'])).toThrow(TypeError);
7171
});
7272

73-
it("doesn't throw an error when passing what seems like an invalid URL", () => {
74-
expect(() => addParams('something=other', 'broken input')).toThrow(
75-
/Invalid URL: broken input/
76-
);
73+
it('throws an error when passed an invalid URL', () => {
74+
expect(() =>
75+
addParams('something=other', 'not a relative or absolute URL')
76+
).toThrow(/Invalid URL: not a relative or absolute URL/);
7777
});
7878

79-
it("doesn't throw an error when passing a relative path as the second argument", () => {
79+
it('gracefully handles a relative path as the second argument', () => {
80+
// Invariant: Jest environment sets up location like so:
81+
expect(location.href).toBe('http://localhost/');
82+
8083
expect(addParams('something=other', '/hello-there')).toEqual(
81-
`${location.href}hello-there?something=other`
84+
`http://localhost/hello-there?something=other`
8285
);
8386
});
8487

8588
it('changes the base URL if the second argument is an absolute URL', () => {
8689
const url = addParams('something=other', 'https://liferay.com');
90+
8791
expect(url).toEqual('https://liferay.com/?something=other');
8892
});
8993
});

0 commit comments

Comments
 (0)