This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gareth Rogers
committed
Mar 11, 2013
1 parent
5d75036
commit 5ce6404
Showing
3 changed files
with
41 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,17 @@ | ||
var GOVUK = GOVUK || {}; | ||
GOVUK.performance = {}; | ||
|
||
GOVUK.performance.addToNamespace = function (name, obj) { | ||
if (GOVUK.performance[name] === undefined) { | ||
GOVUK.performance[name] = obj; | ||
} | ||
else { | ||
throw new Error("There is already a key: '" + name + "' in the namespace."); | ||
} | ||
}; | ||
|
||
|
||
GOVUK.performance.close = function () { | ||
GOVUK.performance.addToNamespace = undefined; | ||
GOVUK.performance.close = undefined; | ||
}; |
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,22 @@ | ||
describe("namespacing", function () { | ||
|
||
it("should add to the namespace", function () { | ||
GOVUK.performance.addToNamespace("foo", function () { return "bar"; }); | ||
expect(GOVUK.performance.foo()).toBe("bar"); | ||
}); | ||
|
||
|
||
it("should throw an exception if the name already exists and not add to the namespace", function () { | ||
expect(function () { GOVUK.performance.addToNamespace("foo", "blah blah blah"); }) | ||
.toThrow(new Error("There is already a key: 'foo' in the namespace.")); | ||
expect(GOVUK.performance.foo()).toBe("bar"); | ||
}); | ||
|
||
|
||
it("should remove namespace helpers when closed", function () { | ||
GOVUK.performance.close(); | ||
expect(function () { GOVUK.performance.addToNamespace("test", {}); }).toThrow("Property 'addToNamespace' of object #<Object> is not a function"); | ||
expect(function () { GOVUK.performance.close(); }).toThrow("Property 'close' of object #<Object> is not a function"); | ||
}); | ||
|
||
}); |
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