ekino / veggies

:sparkles: :rocket: Veggies is an awesome cucumberjs library for API/CLI testing. Great for testing APIs built upon Express, Koa, HAPI, Loopback and others. It's also the perfect companion for testing CLI applications built with commander, meow & Co.
https://ekino.github.io/veggies/
MIT License
90 stars 18 forks source link

Adding to definitions.js locally reports this.httpApiClient as undefined #25

Closed mnishizawa closed 6 years ago

mnishizawa commented 6 years ago

Do you want to request a feature or report a bug? Possible bug or I may just be making a mistake

What is the current behavior? The total contents of my support/definitions.js file is:

'use strict'

const { defineSupportCode } = require('cucumber')
const { STATUS_CODES } = require('http')

defineSupportCode(({ Given }) => {
    Given(/^(?:I )?pick response body as (.+)$/, function(key) {
        const response = this.httpApiClient.getResponse()
        const body = response.body

        this.state.set(key, body)
    })

    Given(/^[Aa]n authenticated user named (.+) with password (.+) in (.+)$/, function(userName, password, system) {
        this.httpApiClient.setHeader("appid", "automation");
        this.httpApiClient.setHeader("apiVersion", "1");
        this.httpApiCleint.setHeader("Content-Type", "application/json");
        this.httpApiClient.setJsonBody({
            "userName": userName,
            "password": password,
            "system"  : system
        });
        this.httpApiClient.makeRequest(POST, this.state.populate("/auth", baseUrl));
    })
 })

The first Given statement seems fine, I'm able to use it and there are no problems.

However, when I try to use the second statement, basically allowing us to more succinctly test our authorized endpoints, I get the following:

Given An authenticated user named dev@myapp.com with password Tinh4t! in Mail
       TypeError: Cannot read property 'setHeader' of undefined

What is the expected behavior? I am expecting to be able to reference this.httpApiClient

Please provide your exact configuration and mention your veggies, node, yarn/npm version and operating system. OS: MacOS High Sierra Node: 8.5.0 Veggies: Only the github repo is in the package.json, but we just started playing with this 2 days ago Cucumber: ^3.2.1

mnishizawa commented 6 years ago

The problem is mine, I misspelled httpApiClient on the Content-Type line. Helps when you aren't tired.