Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Unit Test javascript files in AEM

Avatar

Avatar
Validate 10
Level 2
FernandoUchiyam
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 10
Level 2
FernandoUchiyam
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
FernandoUchiyam
Level 2

22-01-2019

Hi guys,

I have a requirement here in my company that we have to do unit tests on our Javascript files. What do you recommend? (we are already unit testing Java Sling Models, now we want to test javascript code).

When I say Javascript I mean the JS files that are inside Clientlibs of custom developed Components. We want to do 100% coverage, so we need some way to build a report coverage too.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

22-01-2019

My bad, I probably overlooked javascript keyword

You can use any industry standard js unit testing tools with AEM, e.g. karma/jasmine etc.

Use frontend-maven-plugin to integrate it with node/npm  or  About Node.js Maven Plugin | Node.js Maven Plugin

check -

GitHub - eirslett/frontend-maven-plugin: "Maven-node-grunt-gulp-npm-node-plugin to end all maven-nod...

e.g. add this to pom.xml

<execution>

  <id>javascript tests</id>

  <goals>

  <goal>karma</goal>

  </goals>

   <!-- optional: the default plase is "test". Some developers

  choose to run karma in the "integration-test" phase. -->

  <phase>test</phase>

  <configuration>

   <!-- optional: the default is "karma.conf.js" in your working directory -->

  <karmaConfPath>src/test/javascript/karma.conf.ci.js</karmaConfPath>

  </configuration>

</execution>

Answers (4)

Answers (4)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

627 likes

Total Posts

596 posts

Correct Reply

234 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

627 likes

Total Posts

596 posts

Correct Reply

234 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

17-10-2019

Yes, it is possible to run JavaScript unit test directly on the logic that is written in your client library. Utilising tools like Jest and the Maven Front end Plugin, these tools will enable you to write tests.

This is great because you can write tests for custom touch ui dialogue hooks, etc...

examples shows here: https://sourcedcode.com/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

22-01-2019

To learn more about AEM Testing - see this video

Avatar

Avatar
Validate 10
Level 2
FernandoUchiyam
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 10
Level 2
FernandoUchiyam
Level 2

Likes

4 likes

Total Posts

39 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
Applaud 5
View profile
FernandoUchiyam
Level 2

22-01-2019

Hi, Hobbes.js is a tool for UI Testing.

I would like to know more about Unit Test.

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

22-01-2019

For js testing, check -

Hobbes.js Index

Testing Your UI

you could also use npm package for node integration, if applicable - hobbes - npm