I'm exploring tests for my React build and in general - all works as expected.
I have question about "Received" info part of test.
Do I really need whole info? Because it looks redundant.
For example I do simple checking for DOM elements and expect to have 1 and got 2 - I'm happy with this part, but how can I hide all those spaghetti?
Jest part of package.json:
"jest": {
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
"unmockedModulePathPatterns": [
"react",
"enzyme",
"jest-enzyme"
]
},
There are a couple of things that you can do,
Check if the find elements exits like
expect(wrapper.find(".testing-purposes").exists()).toBe(true);
Check the length of the return elements like
expect(wrapper.find(".testing-purposes").length).toBe(2);
According to the documentation:
Use .toHaveLength to check that an object has a .length property
and it is set to a certain numeric value.
This is especially useful for checking arrays or strings size.
which doesn't seem to be the case for you
You are comparing the whole shallow rendered. The toHaveLength hasn't worked consistently for me.
Try:
expect(wrapper.find(".testing-purposes").length).toBe(2);
Related
I'd like to start by asking Mapbox - please - to put documentation on their site that explains how to set up and start doing a simple test. There are many tests in their code on Github, but after days of reading and attempting to test I have failed to understand how they work.
I have a very simple method that:
updates some geoJson with some new coordinates and a new heading (rotation) for a marker.
uses setSource to set the changed Json to the Map
I would like to run my little method in a test and then check that the new coordinates have arrived in the Map.
Should be a piece of cake!
Now a Map needs a browser or similar. Yes, there's jsdom, which is almost certainly what is needed, but I have not discovered how you give the dom to the Map.
If I try to instantiate either window, which I found in mapbox-js utils, or Map, I get
ReferenceError: self is not defined. - 'self' appears to be the window object.
I use mocha, with babel 7, for what it's worth, but I think that all I need is to solve the mystery of setting up a Map instance so that I can then interrogate it.
Any help would be gratefully received.
New to ember.js -- used http://yoember.com/ to create a Demo ember.js site. I'm trying to figure out how to use Protractor to test certain elements, but I'm encountering issues specifying them.
Most, but not all, elements (buttons, text areas, etc) have a serialized id value: id='ember###' that changes every time the page is reloaded, which makes it impossible to indicate some elements in Protractor (like, element(by.id('ember557')).sendKeys('foo');).
Running a command like the one above will return the error: Failed: No element found using locator: By(css selector, *[id="ember557"]), which is due to the 3-digit id value changing.
In my demo app, I was able to go into the /app/templates/components/ file for that page and manually add something like id='name' into the handlebars input and was able to successfully find and test that element in Protractor.
This isn't ideal though, and I'd like to find a way to test sites that I don't have the ability to modify the html of.
Can anyone help me wrap my head around this? Thanks.
I'm evaluating Calabash coming from an Appium & Selenium background.
In Selenium i can simply assign the .attribute("value") to a variable and then do what I want with it. I'm looking for something similar in Calabash.
Specifically in an Android app (although I am looking for a cross platform solution) I have an EditText that I can query with :text and I can see the value in the output i.e.
irb(main):008:0> query("EditText",:text)
[
[0] "17512"
]
How can I perform the same function as a step definition in calabash and assign the output (i.e. 17512) to a variable?
Any advice is much appreciated.
This post helped me get what I needed: https://sqa.stackexchange.com/questions/8385/how-to-get-the-text-to-verify-for-edittext-in-calabash-android
Particularly actual_email = query("EditText id:'txt_email'", :text).first
I have a Django project which is entering its fourth year of development. Over those four years, a number of URLs (and therefore view functions) have become obsolete. Instead of deleting them as I go, I've left them in a "just in case" attitude. Now I'm looking to clean out the unused URLs and unused view functions.
Is there any easy way to do this, or is it just a matter of grunting through all the code to figure it out? I'm nervous about deleting something and not realizing it's important until a few weeks/months later.
The idea is to iterate over urlpatterns and check that the status_code is 200:
class BasicTestCase(TestCase):
def test_url_availability(self):
for url in urls.urlpatterns:
self.assertEqual(self.client.get(reverse('%s' % url.name)).status_code,
200)
I understand that it might not work in all cases, since there could be urls with "dynamic" nature with dynamic url parts, but, it should give you the basic idea. Note that reverse() also accepts arguments in case you need to pass arguments to the underlying view.
Also see: Finding unused Django code to remove.
Hope that helps.
You are looking for coverage, which is basically "how much of the code written is actually being used".
Coverage analysis is usually done with tests - to find how what percentage of your code is covered by tests - but there is nothing stopping you to do the same to find out what views are orphaned.
Rather than repeat the process, #sk1p already answered it at How to get coverage data from a django app when running in gunicorn.
I'm trying to camelize an extracted value from an ember view, and I was hoping to get the lower case camelized form of a string as is written here http://docs.emberjs.com/symbols/Ember.String.html#.camelize
However, what I'm getting back is the capitalized version of it (the extracted value started off as Capitalized).
Try this Ember.String.camelize("my lovely property") which gives you myLovelyProperty
I can confirm that My-Lovely-Property isn't converted to myLovelyProperty. Nor is MY-LOVELY-PROPERTY -- it leaves those "OVELY" "ROPERTY" caps alone too and yields MYLOVELYPROPERTY which certainly doesn't feel like camel case. I'm not sure if that behavior is intended or not, but it seems neither this case nor yours is covered by the test examples.
If you or anyone else believes strongly that such cases should be covered in some way, perhaps submit a github issue or PR? Otherwise, for the case you describe you can use an expression like str.charAt(0).toLowerCase() + str.substr(1).camelize().