-
Notifications
You must be signed in to change notification settings - Fork 0
Description
i want to explore ideas for a mocking plugin. I'd like to crib off of jest here. i'd like to consider using import syntax to mock certain modules. I had the earlier idea to use a pseudo-protocol but rejected it outright when i understood that sometimes unmentioned dependencies also need mocking. Say, a situation where A depends on B and B depends on C and C needs mocking. But I think pseudo-protocols can still work here, and make more sense than imperative calls like what jest does. We just need to mention the things that need mocked.
import { A } from './A';
import { B } from 'mock:./B';
import "mock:./C";Sometimes there is a need to mock finer grained things like methods. This would require an imperative API of some sort, I believe.
Another idea maybe worth capturing is using hash fragments instead of pseudoprotocols. This has the advantage of leaving room on the right for mentioning the path to a mock implementation.
import { A } from '../src/A';
import { B } from './B#mock=./mocks/A/B.mock';
import './C#mock=./mocks/A/C.mock';Ugly as sin, but gets the job done.
Also, seems eminently possible to combine these ideas:
import { A } from '../src/A';
import { B } from 'mock:./B#./mocks/A/B.mock';
import 'mock:./C#./mocks/A/C.mock';Explore this space thoroughly and come up with the best plan before proceeding