Skip to content

Instantly share code, notes, and snippets.

@Nkzn
Created April 1, 2020 02:55
Show Gist options
  • Save Nkzn/900d4c970dbff16b4cbb06c2ba9bc77b to your computer and use it in GitHub Desktop.
Save Nkzn/900d4c970dbff16b4cbb06c2ba9bc77b to your computer and use it in GitHub Desktop.
ES Modulesで「プライベートメソッドをテストする」をやりたいとき
export function publicFunction() {
}
function complexPrivateFunctionA() {
}
function complexPrivateFunctionB() {
}
function complexPrivateFunctionC() {
}
export const __dangerousExportForTesting = {
complexPrivateFunctionA,
complexPrivateFunctionB,
complexPrivateFunctionC,
};
import {
publicFunction,
__dangerousExportForTesting,
} from './functions';
describe('publicFunction', () => {
test('hoge', () => {
publicFunction();
});
});
describe('complexPrivateFunctionA', () => {
const { complexPrivateFunctionA } = __dangerousExportForTesting;
test('hoge', () => {
complexPrivateFunctionA();
});
});
describe('complexPrivateFunctionB', () => {
const { complexPrivateFunctionB } = __dangerousExportForTesting;
test('hoge', () => {
complexPrivateFunctionB();
});
});
describe('complexPrivateFunctionC', () => {
const { complexPrivateFunctionC } = __dangerousExportForTesting;
test('hoge', () => {
complexPrivateFunctionC();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment