Skip to content

Commit

Permalink
localStorge.saveの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
erukiti committed Apr 29, 2019
1 parent 07f8753 commit 765864e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion jest.config.js
Expand Up @@ -11,5 +11,7 @@ module.exports = {
testMatch: ['**/src/**/*.test.(ts|tsx|js)'],
testPathIgnorePatterns: ['/node_modules/'],
preset: 'ts-jest',
// setupFiles: ['jest-localstorage-mock', 'jest-date-mock']
setupFiles: ['jest-localstorage-mock']
}

//, 'jest-date-mock'
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
]
},
"devDependencies": {
"jest-localstorage-mock": "^2.4.0",
"ts-jest": "^24.0.2"
}
}
9 changes: 9 additions & 0 deletions src/adapters/local-storage.test.ts
@@ -0,0 +1,9 @@
import { createTipsLocalStorage } from "./local-storage";

describe("save", () => {
test("ローカルストレージにtips-<ID>でメッセージが格納される", () => {
const tipsLocalStorage = createTipsLocalStorage();
tipsLocalStorage.save("ID", "hoge");
expect(localStorage.getItem("tips-ID")).toBe("hoge");
});
});
10 changes: 10 additions & 0 deletions src/adapters/local-storage.ts
@@ -0,0 +1,10 @@
import { TipsPort } from "../domains/tips";

export const createTipsLocalStorage = (): TipsPort => {
const save: TipsPort["save"] = async (id, message) => {
localStorage.setItem(`tips-${id}`, message);
};
const findById = async () => ({id: 'dummy', message: 'dummy'});
const findAll = async () => [];
return { save, findAll, findById };
};
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -5312,6 +5312,11 @@ jest-leak-detector@^24.7.0:
dependencies:
pretty-format "^24.7.0"

jest-localstorage-mock@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jest-localstorage-mock/-/jest-localstorage-mock-2.4.0.tgz#c6073810735dd3af74020ea6c3885ec1cc6d0d13"
integrity sha512-/mC1JxnMeuIlAaQBsDMilskC/x/BicsQ/BXQxEOw+5b1aGZkkOAqAF3nu8yq449CpzGtp5jJ5wCmDNxLgA2m6A==

jest-matcher-utils@^24.7.0:
version "24.7.0"
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-24.7.0.tgz#bbee1ff37bc8b2e4afcaabc91617c1526af4bcd4"
Expand Down

0 comments on commit 765864e

Please sign in to comment.