Skip to content

Commit

Permalink
fix(test): update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham2811 committed Sep 26, 2024
1 parent 666e9f2 commit 34c79a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "subapp-redux",
"comment": "replace createStore of redux by configureStore of @reduxjs/toolkit",
"type": "major"
}
],
"packageName": "subapp-redux"
}
56 changes: 30 additions & 26 deletions packages/subapp-redux/test/spec/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"use strict";

const subappRedux = require("../..");
const { getReduxCreateStore, clearSharedStore, setStoreContainer } = require("../../src/shared");
const {
getReduxCreateStore,
clearSharedStore,
setStoreContainer,
} = require("../../src/shared");
const { getSubAppContainer } = require("subapp-util");

const SimpleReducer = (x = true) => x;

describe("subapp-redux", function() {
describe("subapp-redux", function () {
afterEach(() => {
clearSharedStore();
});
Expand All @@ -18,7 +22,7 @@ describe("subapp-redux", function() {

it("should create store based on reduxCreateStore if it is passed", () => {
const store = getReduxCreateStore({
reduxCreateStore: () => 5
reduxCreateStore: () => 5,
})({});

expect(store).to.equal(5);
Expand All @@ -27,12 +31,12 @@ describe("subapp-redux", function() {
it("should use true reduxShareStore to name and persist primary store instance", () => {
const defaultStore = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: true
reduxShareStore: true,
})({});

const defaultStore2 = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: true
reduxShareStore: true,
})({});

expect(defaultStore).to.equal(defaultStore2);
Expand All @@ -41,12 +45,12 @@ describe("subapp-redux", function() {
it("should not conflate true reduxShareStore with named reduxShareStore", () => {
const defaultStore = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: true
reduxShareStore: true,
})({});

const green = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: "green"
reduxShareStore: "green",
})({});

expect(defaultStore).to.not.equal(green);
Expand All @@ -55,12 +59,12 @@ describe("subapp-redux", function() {
it("should use string reduxShareStore to name and persist store instances", () => {
const blue = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: "blue"
reduxShareStore: "blue",
})({});

const blue2 = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: "blue"
reduxShareStore: "blue",
})({});

expect(blue).to.equal(blue2);
Expand All @@ -69,12 +73,12 @@ describe("subapp-redux", function() {
it("should not conflate two different reduxShareStore keys", () => {
const blue = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: "blue"
reduxShareStore: "blue",
})({});

const green = getReduxCreateStore({
reduxReducers: { a: SimpleReducer },
reduxShareStore: "green"
reduxShareStore: "green",
})({});

expect(blue).to.not.equal(green);
Expand All @@ -84,16 +88,16 @@ describe("subapp-redux", function() {
expect(() =>
getReduxCreateStore({
reduxCreateStore: () => 5,
reduxShareStore: true
reduxShareStore: true,
})({})
).throws("cannot have reduxCreateStore");
});

it("should not allow functional reducers in a shared store", () => {
expect(() => {
getReduxCreateStore({
reduxReducers: x => x,
reduxShareStore: true
reduxReducers: (x) => x,
reduxShareStore: true,
})({});
}).to.throw();
});
Expand All @@ -102,13 +106,13 @@ describe("subapp-redux", function() {
getReduxCreateStore({
name: "app1",
reduxReducers: { pi: (x = 3.146) => x },
reduxShareStore: true
reduxShareStore: true,
})({});

const store = getReduxCreateStore({
name: "app2",
reduxReducers: { sqrt2: (x = 1.414) => x },
reduxShareStore: true
reduxShareStore: true,
})({});

const state = store.getState();
Expand All @@ -120,17 +124,17 @@ describe("subapp-redux", function() {
getReduxCreateStore({
name: "app1",
reduxReducers: { pi: (x = 3.146) => x },
reduxShareStore: true
reduxShareStore: true,
})({});

const app2 = {
name: "app2",
reduxReducers: {
sqrt2: (x = 1.414) => {
return x;
}
},
},
reduxShareStore: true
reduxShareStore: true,
};
const store = getReduxCreateStore(app2)({});

Expand All @@ -141,11 +145,11 @@ describe("subapp-redux", function() {
{
sqrt2: () => {
return 11;
}
},
},
app2
);
store.dispatch({ type: 1 });
store.dispatch({ type: "1" });
const state2 = store.getState();
expect(state2.sqrt2).to.equal(11);
});
Expand All @@ -156,7 +160,7 @@ describe("subapp-redux", function() {
const store = getReduxCreateStore({
name: "app1",
reduxReducers: { pi: (x = 3.146) => x },
reduxShareStore: true
reduxShareStore: true,
})({});

expect(container.namedStores._.store).equals(store);
Expand All @@ -169,7 +173,7 @@ describe("subapp-redux", function() {
name: "app",
reduxReducers: () => {
return { v: 1 };
}
},
})({});
expect(container.namedStores).to.deep.equal({});
const state = store.getState();
Expand All @@ -184,8 +188,8 @@ describe("subapp-redux", function() {
reduxReducers: {
a: () => {
return 2;
}
}
},
},
})({});
expect(container.namedStores).to.deep.equal({});
const state = store.getState();
Expand All @@ -196,7 +200,7 @@ describe("subapp-redux", function() {
const container = {};
setStoreContainer(container);
const store = getReduxCreateStore({
name: "app"
name: "app",
})({ a: 1 });
expect(container.namedStores).to.deep.equal({});
const state = store.getState();
Expand Down

0 comments on commit 34c79a0

Please sign in to comment.