Skip to content

fix: storeName can be used in createInstance and instance functions. #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
style: indentations changed, 4 spaces to 2 spaces
  • Loading branch information
hozkok committed Jul 3, 2016
commit 706dd6178e1431762e04ddcc5cd67d5288b7b37c
129 changes: 54 additions & 75 deletions tests/angular-localForage.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,92 +479,71 @@ describe('Module: LocalForageModule', function() {
});

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this added code is indented 4 spaces, but the rest of the code base is 2-space indent. Please conform, to keep a consistent style.

describe("createInstance", function () {
beforeEach(function () {
$localForage.createInstance({
name: 'DUPLICATE_INSTANCE_NAME'
});
});
it('should create a new instance', function () {
expect($localForage.createInstance({
name: 'TEST_INSTANCE'
})).toBeDefined();
beforeEach(function () {
$localForage.createInstance({
name: 'DUPLICATE_INSTANCE_NAME'
});
});
it('should create a new instance', function () {
expect($localForage.createInstance({
name: 'TEST_INSTANCE'
})).toBeDefined();
});

it('should throw error if trying to create duplicate instance.',
function () {
expect($localForage.createInstance.bind($localForage, {
name: 'DUPLICATE_INSTANCE_NAME'
})).toThrowError(/already defined/);
});
it('should throw error if trying to create duplicate instance.',
function () {
expect($localForage.createInstance.bind($localForage, {
name: 'DUPLICATE_INSTANCE_NAME'
})).toThrowError(/already defined/);
});

it('should create instance with same name, different storeName',
function () {
expect($localForage.createInstance.bind($localForage, {
name: 'DUPLICATE_INSTANCE_NAME',
storeName: 'DIFFERENT_STORE_NAME'
})).not.toThrowError(/already defined/);
});
it('should create instance with same name, different storeName',
function () {
expect($localForage.createInstance.bind($localForage, {
name: 'DUPLICATE_INSTANCE_NAME',
storeName: 'DIFFERENT_STORE_NAME'
})).not.toThrowError(/already defined/);
});
});

describe("instance", function () {
var $q, interval;
beforeEach(function () {
$localForage.createInstance({
name: 'TEST_INSTANCE_1'
});
$localForage.createInstance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_1'
});
$localForage.createInstance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_2'
});
inject(function (_$q_) {
$q = _$q_;
});
interval = triggerDigests();
beforeEach(function () {
$localForage.createInstance({
name: 'TEST_INSTANCE_1'
});

afterEach(function () {
stopDigests(interval);
$localForage.createInstance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_1'
});

it('should get instance by name', function () {
expect($localForage.instance({
name: 'TEST_INSTANCE_1'
})).toBeDefined();
$localForage.createInstance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_2'
});
});

it('should throw exception if instance not exists', function () {
expect($localForage.instance.bind($localForage, {
name: 'NON_EXISTENT'
})).toThrowError();
});
it('should get instance by name', function () {
expect($localForage.instance({
name: 'TEST_INSTANCE_1'
})).toBeDefined();
});

it('should get instances with same name, different storeNames',
function (done) {
var instance1 = $localForage.instance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_1'
});
var instance2 = $localForage.instance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_2'
});
$q.all([
instance1.setItem('key', 'val1'),
instance2.setItem('key', 'val2')
]).then(function () {
return $q.all([
instance1.getItem('key').then(function (val) {
expect(val).toEqual('val1');
}),
instance2.getItem('key').then(function (val) {
expect(val).toEqual('val2');
})
]);
}).then(done);
it('should throw exception if instance not exists', function () {
expect($localForage.instance.bind($localForage, {
name: 'NON_EXISTENT'
})).toThrowError();
});

it('should get instances with same name, different storeNames',
function () {
var instance1 = $localForage.instance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_1'
});
var instance2 = $localForage.instance({
name: 'TEST_INSTANCE_2',
storeName: 'TEST_STORE_NAME_2'
});
expect(instance1).not.toBe(instance2);
});
});
});