Latest Update
I discovered that placing my KioskTemplates.html file at the root of my testing folder resolved the issue. However, I am still curious if there is a way to use a relative path instead. Do I need to adjust the "basePath" in my karma.conf file to achieve this?
The Current Scenario:
- I have a Typescript module that requires testing with Karma/Jasmine
- Within this module, there is a class containing a method named renderUI
- This method utilizes a jQuery $.get method to retrieve a Mustache template from an HTML file
- My objective is to test this functionality using Karma/Jasmine
- Including the file in karma.conf.js with "included:false, serve:true"
- I am attempting to proxy it as "/KioskTemplates.html" to fulfill the $.get request
Challenges Faced:
- The test continues to fail with a
WARN [web-server] : 404: /base/KioskTemplates.html
- Even after trying an absolute path to include the file, I am unable to locate it on the web server.
If you have any suggestions or assistance, please share!
Here is the relevant code:
Below is the renderUI method snippet:
public renderUI() {
var visitReasonData = this.setupVisitReasonData()
var thePromise:Observable<any> = new Observable(observer => {
$.get('KioskTemplates.html', templates => {
let theTemplate = $(templates).filter('#tmpVisitReasons').html();
let html = Mustache.to_html(theTemplate, visitReasonData);
$('#tblVisitReasons').html(html);
applyFontSize('.Panels', this.page);
changeColorsFromArray([
'.fa-circle-thin','.fa-check','.fa-square-o','.fa-check-square-o','.fa-arrow-circle-o-right','.fa-arrow-circle-o-left','.fa-text-height'],
'.formbutt',
'background-color'
)
window.scrollTo(0, 0);
}).done(() => { observer.next(true) })
})
return thePromise
}
Additionally shared is my karma.conf.js configuration:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine','karma-typescript','fixture'],
files: [
'../secrets.ts',
'tests/*.ts',
"../node_modules/font-awesome/css/**/*.css",
"../../../../Websites/VirtualOneStop/Vos/vosnet/JavaScript/StaffEfficiency/source/*.ts",
"../../../../Websites/VirtualOneStop/Vos/vosnet/JavaScript/StaffEfficiency/entry-points/*.ts",
"tests/**/*.json",
{ pattern: '../../../../Websites/VirtualOneStop/Vos/vosnet/OneStopEfficiency/KioskTemplates.html', included:true, served:true }
],
proxies : {
'/KioskTemplates.html':'/base/KioskTemplates.html'
},
karmaTypescriptConfig: {
compilerOptions: {...},
include: [...],
exclude: [...]
},
preprocessors: {
"../../../../Websites/VirtualOneStop/Vos/vosnet/JavaScript/StaffEfficiency/source/*.ts":['karma-typescript'],
...
},
reporters: ['dots'],
jsonFixturesPreprocessor: {...},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
})
}
The encountered error:
Chrome 60.0.3112 (Windows 7 0.0.0): Executed 218 of 218 (1 FAILED) (6.172 secs / 5.603 secs)
21 09 2017 11:23:10.577:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.5.2
...
LOG: true
...
LOG: 0
.
Chrome 60.0.3112 (Windows 7 0.0.0): Executed 218 of 218 SUCCESS (1.241 secs / 0.62 secs)