dojo.byId intern unit testing error

384
3
03-19-2020 09:07 AM
sandhyabaratam
New Contributor

Hi,

I am using intern for unit testing of my custom widget.
I am getting error when I use dojo.byId() in any method of custom widget code. can you please let me know if i have to import any specific library in test class?
If I comment this line dojo.byId() in widget code, Test is getting passed.


1.I have added dojo dependency in node_modules->package.json ->dependencies section
"dojo":"^1.14.0"


2.imported below modules in test class ----
define([
'intern!object',
'intern/chai!assert',
'app/testRoute/Methods',"dojo/_base/declare",
"dojo/dom-construct", "dojo/_base/window", "dojo/_base/lang","esri/layers/FeatureLayer",
'dojo/on',
"dojo/_base/array", "dojo/Deferred"
], function(registerSuite, assert,methods,declare,domConstruct, win, lang,FeatureLayer, on,
arrayUtils, Deferred) {}


3.widget code ,

processCsvData()---
dojo.byId("progressBar").style.display = "none";

unit testing Error:
PASS: Test getHashInput (1ms)
FAIL: Test processCsvData (2ms)
TypeError: Cannot read property 'length' of undefined
at Test processCsvData [as test] <tests/unit/testRoute_test.js:114:33>
at <__intern/lib/Test.js:181:24>
at <__intern/browser_modules/dojo/Promise.js:156:41>
at runCallbacks <__intern/browser_modules/dojo/Promise.js:19:22>
at <__intern/browser_modules/dojo/Promise.js:103:21>
at run <__intern/browser_modules/dojo/Promise.js:51:33>
at CallbackQueue.drain <__intern/browser_modules/dojo/CallbackQueue.js:39:35>
at MutationObserver.<anonymous> <__intern/browser_modules/dojo/nextTick.js:52:27>

Regards,
Sandhya

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Since dojo.byId has been deprecated, you should be using dojo/dom::byId

0 Kudos
sandhyabaratam
New Contributor

Hi Ken,

thank you for your reply.

I changed it to dom.byId instead of dojo.byId in widget code and imported dojo/dom module in both widget and test class. but still getting the same error while executing unit test.

0 Kudos
KenBuja
MVP Esteemed Contributor

Did you see this discussion about unit testing with DOM items?

But do you need to test that? The number one point in last year's tech session on unit testing is Don't Test Other People's Code! This part of the video talks about using mocking, spies, or fakes to get around that.

0 Kudos