jeudi 1 mars 2018

Using Chai with Jest + Typescript

So, I'm trying to use chai expect library while running Jest with Typescript but I'm not being able to.

What I'm actually trying to do is something similar to this: https://medium.com/@RubenOostinga/combining-chai-and-jest-matchers-d12d1ffd0303

But I'm having no luck achieving this with Typescript. I'm quite new to the JS / TS, coming from C, Go and Swift, so I might be missing something here.

Can someone give me any directions to this this with TS while having autocomplete and no type errors working?? Thanks in advance!!

How do I optionally slow down cucumber (ruby) tests?

I have tried googling, but had no luck. Maybe I just don't know the terms to search for...

Recently we made some changes to the environment, and now tests that use to run without issue kill the service. We are working to find out why that is happening... but in the meantime, is there a way I could pass a CLI command or something to slow down the tests on demand? (or vice versa, run at full speed on demand) Or maybe build something into a rake task?

I know I could easily add an after hook to sleep between scenarios, but I want to be able to run the tests full blast as well while we are trying to sort out the issue. Adding an after hook would require editing several files every time we wanted to turn the throttling on or off.

Testing Typescript React Component context with enzyme

I have a React Component in Typescript something like this

import * as React from 'react';
import * as PropTypes from 'prop-types';

export class MyComponent extends React.Component<{}, {}> {

    context = {
        callBack: Function
    }
    static contextTypes = {
        callBack: React.PropTypes.Func
    };

    render() {
        return (
            <button onClick={this.callContextCallback}>Call Context</button>
        );
    }

    callContextCallback = () => {
        this.context.callBack();
    }
}

And I have written my tests for the Component

import { mount, shallow } from 'enzyme'
import * as React from "react"
import { MyComponent } from "./MyComponent"

describe(`<MyComponent />`, () => {

    let callBackMock = jest.fn()

    beforeEach(() => {
        wrapper = mount(
            <MyComponent />, {
                context: {
                    callBack: callBackMock
                }
            }
        )
    })

    it(`should call context Callback on clicking button`, () => {
        wrapper.find('button').simulate('click')
        expect(callBackMock).toHaveBeenCalledTimes(1)
    })
})

when I run my tests, The test fails with function not being called.

I even tried mocking spying on the callContextCalback function

    it(`should call context Callback on clicking button`, () => {
        let instance = wrapper.instance()
        const spy = jest.spyOn(instance, 'callContextCallback')
        instance.forceUpdate();
        wrapper.find('button').simulate('click')
        expect(spy).toHaveBeenCalledTimes(1)
    })

and on running the test I get this error

Error: Uncaught [TypeError: Cannot read property 'context' of undefined]
TypeError: Cannot read property 'context' of undefined

How do I test the context callBack function?

testng demo for reference

below are the sample demo code for testng beginners

   package test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class TestNgDemo {
    @BeforeSuite
     public void f6() {
          System.out.println("Before suite is executed");
      }
    @BeforeClass
     public void f5() {
          System.out.println("Before class is executed");
      }
    @BeforeMethod
     public void f4() {
          System.out.println("Before Method is executed");
      }

  @Test(groups={"sanity"})
  public void f() {
      System.out.println("Test is executed");
  }

  @Test(groups={"regression"},priority=2)
  public void test2() {
      System.out.println("Test 2 is executed");
  }

  @Test(dependsOnMethods ={"test4"},groups={"regression"},priority=1)
  public void test3() {
      System.out.println("Test 3 is executed");

  }

  @Test(groups={"regression"})
  public void test4() {
      System.out.println("Test 4 is executed");
      String project="PNC";
      System.out.println(project);
  }
  @Parameters("browser")
  @Test(groups={"regression"},priority=3)
  public void test5(String browser) {
      System.out.println("Test 5 is executed");
      System.out.println("Browser: "+browser);
  }



  @AfterMethod
     public void f3() {
          System.out.println("After Method is executed");
      }

  @AfterClass
     public void f7() {
          System.out.println("after class is executed");
      }

  @AfterSuite
     public void f8() {
          System.out.println("after suite is executed");
      }
}

Below are testng xml code for ref with all the annotations

<?xml version="1.0" encoding="UTF-8"?>
<suite name="example suite 1"  parallel="methods" thread-count="2" >
  <test name="Regression suite 1" >
 <!--  <parameter name = "browser" value="chrome"/> --> 
  <groups>
         <run>
            <include name = "regression" />
         </run>
      </groups> 
    <classes>
      <class name="test.TestNgDemo"/>


    </classes>
 </test>

 <test name="Regression suite 2" >
  <parameter name = "browser" value="firefox"/> 
  <groups>
         <run>
            <include name = "regression" />
         </run>
      </groups>
    <classes>
      <class name="test.TestNgDemo"/>


    </classes>
 </test>

  <test name="Regression suite 3" >
  <parameter name = "browser" value="IE"/> 
  <groups>
         <run>
            <include name = "regression" />
         </run>
      </groups>
    <classes>
      <class name="test.TestNgDemo"/>


    </classes>
 </test> 
</suite>

sdhjhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh lakjfakdj kjjjjjjjjjjjjjjjjjjjjj ksjkjjkdj

dkfjekjfkjk kdjfkjkjkkkkkkkkkkkkkkkkkkkkkkkkkk jdkjfakjdfk dfajlkfjak kjdkjakj jkdjfklajkdfjak kjekla dkfjlakjfk ljkdjfak lkljkdjfa k j kajkdjfdkajfkj dnflakjkdlj arjkjakfj qeieajfdlkjafkj kdjakfjd ajf

Jmeter maven plugin | maven build not failing even if there are failures

I am using JMeter maven plugin 2.6.0 I have a JMeter test plans which contains some test.

I am running the jmx plans through maven build. Even if there are failures, maven build is not getting failed.

I want the maven build to be failed. I am using false in jmeter maven plugin configuration.

No tests found for given includes:

I'm trying to run a simple test that's in my Test class from IDE (Intellij IDEA) and error that pops out is:

No tests found for given includes: org.sample.Test.test

Same thing is happening when I try to run it from command-line. In Intellij, I've set up Build, Execution, Deployment > Build Tools > Gradle > Runner to Gradle Test Runner and I have @Test on my method. Also, I can't run any test (from some other project), so I suppose that it's some configuration problem.

Can someone point me to something, what can I be doing wrong ?

How to test internal controllers without route in Symfony 2

I am trying to reduce redundant code by refactoring template and controller code into reusable components, which I then use via the render(controller('AppBundle:Foo/Bar:baz')) construct inside my other templates.

Of course I would like to test these components. In the examples regarding functional testing, however, an actual route is required to make fake test requests. But my BarController here is purely internal and has no routes attached to it. How can I test this controller?

Creating dummy routes is not always possible, because some of the arguments are model objects that cannot be passed via URL. Am I approaching this the wrong way?