balderdashy/sails

Stub SailsJs helper function which is called with named arguments

Open

#6.986 aberto em 6 de mai. de 2020

Ver no GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (1.953 forks)batch import
help wantedtry this out please

Métricas do repositório

Stars
 (22.778 stars)
Métricas de merge de PR
 (Mesclagem média 23h 44m) (1 fundiu PR em 30d)

Description

Node version: 10.X Sails version (sails): 1.2.3

I'm trying to mock/stub a sailsjs helper function which is called with named arguments. Using sinon library for function mocking.

Example:

function call that needs to be mocked: await sails.helpers.getData.with({})

Tried Solutions:

  1. sinon.stub(sails.helpers, 'getData').returns(true)

issue -> sails.helpers.getData.with is not a function

  1. sinon.stub(sails.helpers.getData, 'with').returns(true)

issue -> Cannot redefine property: with

reason -> non-configurable property is set to false for sails object. And we can't change that.

  1. Tried creating a fake function and adding it to sails.helpers.getData['with'] property

  2. Also tried setting special setters to sails.helpers.getData object with the help of rewire library.

What is the way to stub a helper which is called with named args.

Guia do colaborador