You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello @theKashey, thank you for creating a library which tries to solve the issues of the existing module mocking libraries.
I have read the documentation, both of your articles, as well as a bunch of different issues, but I am really struggling to understand how this library works.
I have read the documentation multiple times, but it is very vague in places and in fact many code examples do not work (often missing closing brackets or braces). I understand there are four different ways to do things given that this library is based off of the four existing legacy libraries, but this makes examples very confusing to understand.
I'm not even sure if the require path within rewiremock() is meant to be the SUT module I am testing or a dependency module of the SUT module. Some examples show the require path as a dependency library, so it implies this should be a dependency, but other examples seem to point to the SUT path itself? I cannot tell if this is a typo in the documentation or if this is one of the four ways to mock.
I have a minimum reproducible repository here, I would be grateful if you can explain what I am doing wrong. I would also prefer to keep the arrange, act, assert test format.
describe('How',async()=>{it('to make this work',async()=>{// Arrangerewiremock(()=>require('./main')).with({'./helper': {helper: ()=>'mock'}}asany)// Actconstresult=main()// Assertequal(result,'mock')})})
The text was updated successfully, but these errors were encountered:
As you've mentioned above - there are a few ways of using rewiremock, and you've mixed a few
There is a correction for your tests to work
import{equal}from"node:assert/strict"import{rewiremock}from"./rewiremock"import{describe,it}from"node:test"-import{ main }from"./main"describe('How',async()=>{it('to make this work',async()=>{-rewiremock.proxy(()=>require('./main'),{+const{main}=rewiremock.proxy(()=>require('./main'),{'./helper': {helper: ()=>'mock'}})
if you want to still have import { main } then you need to use babel plugin AND have rewiremock.proxy or any other rewiremock command at the top level. Basically like jest.mock
If you want to import amended version of main in a test - you need to use a variable rewiremock will give you. Only it will contain amended version.
In short - overriding modules affects structure or your code, the very way files and variables are connected, a different branch, totally new world. You need to get a pointer to that new world - and that is variable rewiremock will give you. You have to store and use it somehow.
Hello @theKashey, thank you for creating a library which tries to solve the issues of the existing module mocking libraries.
I have read the documentation, both of your articles, as well as a bunch of different issues, but I am really struggling to understand how this library works.
I have read the documentation multiple times, but it is very vague in places and in fact many code examples do not work (often missing closing brackets or braces). I understand there are four different ways to do things given that this library is based off of the four existing legacy libraries, but this makes examples very confusing to understand.
I'm not even sure if the require path within
rewiremock()
is meant to be the SUT module I am testing or a dependency module of the SUT module. Some examples show the require path as a dependency library, so it implies this should be a dependency, but other examples seem to point to the SUT path itself? I cannot tell if this is a typo in the documentation or if this is one of the four ways to mock.I have a minimum reproducible repository here, I would be grateful if you can explain what I am doing wrong. I would also prefer to keep the
arrange, act, assert
test format.The text was updated successfully, but these errors were encountered: