18

By scrolling through the Lightning Reference, I've found that there's an Aura Javascript API class called Test. You can find the API docs at https://na24.lightning.force.com/auradocs/reference.app#reference?topic=api:Test.

The docs are...sparse to say the least. The documentation for the Aura open source framework seems to say you can create a MyComponentTest.js file in your component bundle with tests, but no tool I can find successfully deploys a test class to Salesforce.

Is there a way to write test classes into my Controller that are called when certain events fire? Or are we stuck waiting for Salesforce to support this aspect of Aura?

Christian Carter
  • 4,059
  • 18
  • 34

2 Answers2

11

This functionality has not been exposed yet. The Aura framework supports it just fine, but getting that wired into the Dev Tools for Lightning in Salesforce is a bit more involved.

Kris Gray
  • 3,106
  • 17
  • 23
  • 1
    That's what I get for being an early adopter! – Christian Carter Jul 04 '15 at 19:06
  • 1
    Besides being awesome that is. – Kris Gray Jul 04 '15 at 20:13
  • @KrisGray is there any way to create a hybrid development environment that uses a client-side installation of the framework for unit testing while still saving the main resources in the component bundle to Salesforce? – abd3721 Oct 14 '15 at 12:42
  • Yes and no. Aura is open source, and you can setup an instance of it to test with. But you'd have to manually copy over everything after that. See this link for more info on setting it up if you want. https://developer.salesforce.com/blogs/developer-relations/2015/06/running-aura-app-heroku.html – Kris Gray Oct 14 '15 at 20:13
  • 1
    @KrisGray Has there been any update on this? When can we expect official support for unit testing Lightning? – Steve Buikhuizen May 04 '16 at 03:27
  • It keeps getting pushed for Security and Performance. :( – Kris Gray May 09 '16 at 17:30
  • Work is now in progress on this. – Kris Gray Jul 27 '16 at 20:55
  • @KrisGray Is work still in progress on this? – Nathan Hinchey Jan 05 '18 at 23:05
  • Not exactly. We decided to expose testing using the Lightning Testing Service (https://forcedotcom.github.io/LightningTestingService/). That does not use what was referenced here earlier, but is even better since it uses known frameworks like Jasmine and Mocha. – Kris Gray Jan 08 '18 at 20:57
3

I needed a solution for this so I built https://github.com/stevebuik/greased Let me know what you think.

Steve Buikhuizen
  • 423
  • 3
  • 12