@t7/utils
Version:
Utility methods for T7 components.
88 lines (71 loc) • 2.06 kB
JavaScript
var _ = require("./");
// Dependencies.
// Describe test.
describe('storage', function () {
// =========================
// Test for `set` and `get`.
// =========================
it('handles `set` and `get` methods', function () {
// Key/value.
var KEY = 'KEY';
var VALUE = {
foo: 1,
bar: true,
baz: false // Set.
};
_.storage.set(KEY, VALUE);
expect(_.storage.get(KEY)).toEqual(VALUE);
}); // ==================
// Test for `remove`.
// ==================
it('handles `remove` method', function () {
// Key/value.
var KEY = 'KEY';
var VALUE = 'VALUE'; // Set.
_.storage.set(KEY, VALUE);
expect(_.storage.get(KEY)).toBe(VALUE); // Remove.
_.storage.remove(KEY);
expect(_.storage.get(KEY)).toBe(undefined);
}); // ==================
// Test for `clear`.
// ==================
it('handles `clear` method', function () {
// Key/value.
var KEY_1 = 'KEY_1';
var KEY_2 = 'KEY_2';
var VALUE_1 = 'VALUE_1';
var VALUE_2 = 'VALUE_2'; // Set.
_.storage.set(KEY_1, VALUE_1);
_.storage.set(KEY_2, VALUE_2);
expect(_.storage.get(KEY_1)).toBe(VALUE_1);
expect(_.storage.get(KEY_2)).toBe(VALUE_2); // Clear.
_.storage.clear();
expect(_.storage.get(KEY_1)).toBe(undefined);
expect(_.storage.get(KEY_2)).toBe(undefined);
}); // ==========================
// Test for "protected" keys.
// ==========================
it('handles "protected" keys', function () {
// Key/value.
var VALUE = 'VALUE';
expect(function () {
_.storage.set('clear', VALUE);
}).toThrow();
expect(function () {
_.storage.set('getItem', VALUE);
}).toThrow();
expect(function () {
_.storage.set('key', VALUE);
}).toThrow();
expect(function () {
_.storage.set('length', VALUE);
}).toThrow();
expect(function () {
_.storage.set('removeItem', VALUE);
}).toThrow();
expect(function () {
_.storage.set('setItem', VALUE);
}).toThrow();
});
});
;