Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Mike Hingley
    what do you think? I think it's a bit nicer in terms of nesting
    I'd like to know how to test my component's state after the setState is invoked
    (after my async function)
    Is this the correct place to ask usage questions?
    Hi Guys!
    Dinoloop is a Rest API framework for Nodejs powered by Typescript with Dependency Injection.
    Please find the project wiki https://github.com/ParallelTask/dinoloop/tree/master/wiki and please let me know your valuable thoughts on my self project. I would like to hear advice's from community.

    the design goal of dinoloop project is to make C#/Java programmers to easily switch to Nodejs with less learning curve

    dinoloop provides MVC architectural changes with controllers, services and constructor dependency injection,
    SOLID principles are great with OOPS and that is what dinoloop added to typescript using inverifyjs (DI container)

    dinoloop provides bare minimum architecture, you are still free to use all your express objects
    the way express does not abstract you from node, similarly dinoloop does not abstract you from express.

    So adding dinoloop does not harm you anywhere in your project, you can give it a try


    Step 1: Create package.json

    "name": "dinoloop-starter",
    "version": "1.0.0",
    "scripts": {
    "build": "rimraf dist && tsc --p ./tsconfig.json",
    "start": "npm run build && node dist/app.js"
    "dependencies": {
    "dinoloop": "^1.0.0",
    "express": "^4.16.3"
    "devDependencies": {
    "@types/express": "^4.11.1",
    "@types/node": "^7.0.22",
    "rimraf": "^2.5.2",
    "typescript": "~2.4.2"
    Step 2: Create home.controller.ts

    import { ApiController, Controller, HttpGet } from 'dinoloop';

    export class HomeController extends ApiController {

    get(): string {
        return 'Hello World!';

    Step 3: Create app.ts

    import express = require('express');
    import bodyParser = require('body-parser');
    import { Dino } from 'dinoloop';
    import { HomeController } from './controllers/home.controller';

    const app = express();

    // Dino requires express app instance
    // and the base-uri on which dino app to be mounted
    let dino = new Dino(app, '/api');

    // Dino requires express router
    dino.useRouter(() => express.Router());

    // Binds the dino instance to express

    // Start the express server
    app.listen(8088, () => console.log('Server started on port 8088'));
    Run the following npm commands

    npm install - to install dependencies.
    npm start - to start the express app.
    Navigate to http:localhost:8088/api/home/get in browser and you will see the response

    For complete details, please refer https://github.com/ParallelTask/dinoloop-starter and https://github.com/ParallelTask/dinoloop.

    William Lightning
    Is there a way to do something like sinon.stub().callsArgWith(1, {}) the return of the stub is what is returned by the called arg?
    William Lightning
    ended up instead of using stub, wrapping a small function in a spy.
    Robert Main
    Hey folks
    Scott Stern

    Question, when you have a constructor.

    const Test = function() {
      this.testFunc = function () {}

    I have been trying to stub this.testFunc by sinon.stub(Test.prototype, 'testFunc').returns([]);

    But this isnt working, any ideas?

    i see in the docs there are sinon.createStubInstance but i was trying to just use sinon.stub
    Brad Compton (he/him)
    You can instantiate an Object and stub out the method:
    const test = new Test();
    sinon.stub(test, "testFunc")
    Otherwise createStubbedInstance(Test, {testFunc: sinon.stub().returns([])})
    Scott Stern
    ok perfect
    thank you
    wasnt sure if stubbing the instance was a bad idea

    This might be nicer -

      it.only('MessageController calls Messages.Query - returns null', async () => {
        const mockMessages = {
          query: sinon.stub().returns({
            has: sinon.stub().returns({
              with: sinon.stub().returns({
                fetch: sinon.stub().returns({
                  toJSON: sinon.stub().returns('validJSON')
        const SUT = new MessageController(mockMessages)
        // Act
        let result = await SUT.index({request: null, view: {render: sinon.stub()}})
        // Assert

    This syntax in the assertions is too complex for my taste. I would make the setup more complex, but the tests would be simplified.

    beforeEach(function() {
      this.toJSONStub = sinon.stub();
      this.fetchStub = sinon.stub().returns(this.toJSONStub);
      this.withStub = sinon.stub().returns(this.fetchStub);
      this.queryStub = sinon.stub().returns(this.hasStub);
      this.mockMessages = { query:  this.queryStub };
    it('should do a thing', function() {
      // which simplifies the assertions
    Clite Tailor
    How Sinon homepage was generated? Is there any tool because i love the homepage style and really want to make a variant of it on my own repo! :/
    Clite Tailor
    Okey, i found it. Sinon is great!
    Nephtali Rodriguez
    Hi All. I'm attempting to use calledWithMatch but it seems that still only does a fuzzy compare. Is there any way I can do an exact object to object comparison so that if the value of one of the keys is different it returns false?
    Joakim Bajoul Kakaei
    Is this community still active?
    Lars Gyrup Brink Nielsen
    Not very much.
    Sasha Boginsky
    hey! Does anyone here have experience writing tests in sinon with Ruby on Rails and could help me with some questions I have
    Richard Annand
    Not sure if this channel is still active but I am looking for some help with the sinon.stub method
    Derek W. S. Gray
    @rj175 what's the question?
    Brad Compton (he/him)
    I lurk still too
    Arthur Neuman
    test('loopFunction', async (t) => {
      function loopFunction () {
        return true
      const spy = sinon.spy(loopFunction)
      const agent = new Agent({
        Eris: PDiscord,
        agentOptions: {
          loopInterval: 100
      await delay(200)
      loopFunction() // debug
      return agent
    console.log(spy.callCount) returns 0. Why?
    Derek W. S. Gray
    @mets11rap You didn't call the spy
    The spy is a new function
    You should be passing spy in your agentOptions, not loopFunction

    Can someone please help me with below prob:
    I need to stub xyz function
    here is my source file:

    module.exports = (() => { 'use strict'; return ((browser) => { const abc = (duration = constants.SHORT_WAIT) => { console.log('in source : ', xyz()); if (xyz()) { browser.pause(duration); } }; return { abc, xyz }; }); })();

    I stubbed it in test file and showing correct value.
    But in source file, it's not giving stubbed value

    Derek W. S. Gray
    @Babita-Sandooja I don't understand the question.

    I think this stack overflow post explains it: https://stackoverflow.com/questions/35162659/sinon-function-stubbing-how-to-call-own-function-inside-module

    solution they suggested is to refactor the module itself..
    is there some other way as well?

    I think rewire but haven't used it before..
    Brad Compton (he/him)
    Rewire probably won't work because you aren't stubbing the top level function. Is it possible to stub out the whole module, returning the stubbed methods?
    I need to test 1 method in that module.. so stubbing whole module :thought_balloon:
    I don't think that's an option?
    Derek W. S. Gray
    sinon.replace ?
    oh.. so it would replace in the module also
    Derek W. S. Gray
    declare the stub, then use .replace(module, theStub)
    cool.. Let me try with this :thumbsup:
    No, doesn't seem to work
    var fake = sinon.fake.returns(true); sinon.replace(sourceFile, 'xyz', fake);
    when I do console.log(xyz()), It's saying xyz is not defined
    when I do sourceFile.xyz() It's giving true
    but gives false in source file where it's just xyz()
    Derek W. S. Gray
    can you paste your module in a formatted code block
    Just FYI, code refactoring as suggested in stack overflow link worked!
    Derek W. S. Gray
    Oh, I thought that wasn't an option - yes by all means, refactor!