Giter Site home page Giter Site logo

Comments (5)

mttrbrts avatar mttrbrts commented on June 22, 2024 1

This is sound IMO. The concerto module includes test coverage for the usual unstubbed case.

from concerto-tools.

jeromesimeon avatar jeromesimeon commented on June 22, 2024

I'm suspecting the error is triggered by this line in the latest Concerto code:
https://github.com/accordproject/concerto/blob/ad309eaf207f8e57f219d30dd574970e694f2e77/lib/modelmanager.js#L641

from concerto-tools.

jeromesimeon avatar jeromesimeon commented on June 22, 2024

The new Concerto code seems to make use of https://joshmiller.cc/symbol-hasinstance/

from concerto-tools.

jeromesimeon avatar jeromesimeon commented on June 22, 2024

A slightly more specific analysis of what I think the problem is, and a proposed fix.

Why are tests failing:

  1. the behaviour for instanceof in Concerto classes (e.g., for ModelManager) is overridden using the idiom here: https://github.com/accordproject/concerto/blob/ad309eaf207f8e57f219d30dd574970e694f2e77/lib/modelmanager.js#L641
    which means it relies on the presence of a _isModelManager field in the object instance.
  2. sinon's createStubInstance method does not call the constructors which means _isModelManager is not initialised.
  3. as a result tests relying on instanceof (e.g., visitors) will always return false

So I believe the support for instanceof should work as expected when using the library, but will fail in the mocked tests.

I could not find a very official way to mock the constructor through sinon in Stack overflow or in the Sinon documentation. However, the following does work:
Instead of:

let thing = sinon.createStubInstance(ModelManager);

in the tests, use:

let thing = sinon.createStubInstance(ModelManager);
thing._isModelManager = true;

Better suggestions to address this are welcome.

from concerto-tools.

jeromesimeon avatar jeromesimeon commented on June 22, 2024

This is sound IMO. The concerto module includes test coverage for the usual unstubbed case.

Thanks so much for the quick feedback. Corresponding fixes are in PR #24

from concerto-tools.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.