Coder Social home page Coder Social logo

spy constructor about mockito HOT 4 CLOSED

cgarciae avatar cgarciae commented on July 20, 2024
spy constructor

from mockito.

Comments (4)

fibulwinter avatar fibulwinter commented on July 20, 2024

Can you provide an example of use case?

from mockito.

cgarciae avatar cgarciae commented on July 20, 2024

Sometime mocking things like a database driver or a graph-like structure are hard to mock because of their structural or functional complexity, you might instead prefer to use an implementation but still be able to log the objects activity.

Use case

Some script

foo (db) => db.find (...).filter.(...).map(...);

To get the test right, in find you have to tell the mock to return an object that has a filter method, that returns a object that has a map methods. Since nested structures take more effort, it might be easier to use a spy a.

from mockito.

fibulwinter avatar fibulwinter commented on July 20, 2024

Done in 0.10.0

  //spy creation
  var cat = spy(new MockCat(), new Cat());
  //stubbing - before execution
  when(cat.sound()).thenReturn("Purr");
  //using mocked interaction
  expect(cat.sound(), "Purr");  
  //using real object
  expect(cat.lives, 9);   

from mockito.

cgarciae avatar cgarciae commented on July 20, 2024

Excellent!

from mockito.

Related Issues (20)

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.