Skip to content
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

using quibble with momentjs #98

Open
t1a2l opened this issue Jun 4, 2023 · 1 comment
Open

using quibble with momentjs #98

t1a2l opened this issue Jun 4, 2023 · 1 comment

Comments

@t1a2l
Copy link

t1a2l commented Jun 4, 2023

moment is installed with npm, and is used throughout my code not just in the test.
I am trying to call a fake moment function instead of normal one, i am using sinon and was suggested to use quibble for this.
I see in the docs somethign with paths but i am doing this: (it is inside node modules)

const moment = require('moment') const jwt = require('jsonwebtoken'); describe('Admin logged in', () => { //create a sandbox so at the end we can release all fun at once. const sandbox = sinon.createSandbox(); before(async function() { sandbox.stub(jwt, 'verify').callsArgWith(2, null, scope);
how can i achieve a stub of an entire library with this package?

momentjs :
/** @param strict Strict parsing disables the deprecated fallback to the native Date constructor when parsing a string. */ declare function moment(inp?: moment.MomentInput, strict?: boolean): moment.Moment; export = moment; export as namespace moment;

@searls
Copy link
Member

searls commented Jun 5, 2023

You could try mocking the entire moment library (which I don't recommend, since it's a function that returns a bevvy of other functions and you'd just be reimplementing them through a mocking library):

const td = require('testdouble')
const moment = td.replace('moment')

// moment is now a testdouble mock function, faked out by quibble

Or you could create a moment and then fake that, which makes more sense:

const td = require('testdouble')
const moment = require('moment')


const fakeMoment = td.replace('moment')
// fakeMoment is a fake function with the dozens of functions on the moment object replaced with mocks

See testdouble.js for docs. Quibble is available to anyone who wants to use it on its own, but I'd consider the API more advanced, less documented, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants