# How to use credential data with node by node-red-node-test-helper function?

**URL:** <https://discourse.nodered.org/t/how-to-use-credential-data-with-node-by-node-red-node-test-helper-function/57575>\
**Category:** Developing Nodes\
**Created:** [1 February 2022 00:52 UTC](https://discourse.nodered.org/t/how-to-use-credential-data-with-node-by-node-red-node-test-helper-function/57575 "2022-02-01T00:52:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)\
**Post date:** [1 February 2022 00:52 UTC](https://discourse.nodered.org/t/how-to-use-credential-data-with-node-by-node-red-node-test-helper-function/57575/1 "2022-02-01T00:52:32Z")

</div>

Hi all,

I use node-red-node-test-helper for unit testing by creating Node.

I try to send credential data into test function.

Below code is my test function

```auto
it("error token", (done) => {
        const flow = [
            {
                id: "n1",
                type: "node-line-notify",
                name: "node-line-notify",
                message: "test",
                useExternalData: false,
                useImageUrl: false,
                useImageFile: false,
                useSticker: false,
                wires: [["n2"]]
            },
            { id: "n2", type: "helper" }
        ];
        helper.load(nodeLineNotify, flow, {token: "test"}, () => { <<<<<<---- Add credential at here
            const n1 = helper.getNode("n1");
            const n2 = helper.getNode("n2");

            n1.on("call:error", (err) => {
                console.log(n1);
                should.equal(err.lastArg.status, 401);
                should.equal(err.lastArg.payload, "Invalid access token");
                done();
            });
            n1.receive({ payload: "test" });
        });
    });

```

But when I check my creating node "n1", there is not my credential data in node.

```auto
NodeLineNotify {
  id: 'n1',
  type: 'node-line-notify',
  z: undefined,
  g: undefined,
  _closeCallbacks: [],
  _inputCallback: [Function (anonymous)],
  _inputCallbacks: null,
  name: 'node-line-notify',
  wires: [[ 'n2'] ],
  _wireCount: 1,
  send: [Function (anonymous)],
  _wire: 'n2',
  credentials: {}, <<<<<--------- Credential data is empty
  accessToken: undefined,    
  message: 'test',
  useExternalData: false,
  useImageUrl: false,
  imageFullsizeUrl: undefined,
  imageThumbnailUrl: undefined,
  useImageFile: false,
  imageFile: undefined,
  useSticker: false,
  lineStickerPackageId: undefined,
  lineStickerId: undefined,
  disabledPushNotification: undefined,
  _events: [Object: null prototype] { 'call:error': [Function (anonymous)] },
  _eventsCount: 1
}

```

How to use credential data with node by node-red-node-test-helper function? 🤔

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 April 2022 00:52 UTC](https://discourse.nodered.org/t/how-to-use-credential-data-with-node-by-node-red-node-test-helper-function/57575/2 "2022-04-02T00:52:36Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
