Giter Club home page Giter Club logo

Comments (9)

JanithaR avatar JanithaR commented on June 8, 2024

Also not working on Picker from @react-native-community/picker

picker props = {
testID: 'picker',
style: [ { height: 216 }, undefined ],
items: [
{ value: 'USD', label: 'USD', textColor: undefined },
{ value: 'LKR', label: 'LKR', textColor: undefined }
],
selectedIndex: 0,
onChange: [Function],
children: undefined
}

it('should change the selected index when changed', () => {
            const { getByTestId } = setup();
            const picker = getByTestId(testIds.picker);

            console.log('picker props = ', picker.props);

            expect(picker).toHaveProp('selectedIndex', 0);

            fireEvent(picker, 'onValueChange', 'LKR');

            expect(picker).toHaveProp('selectedIndex', 3);
        });

The tests always pass regardless of what I'm passing as the prop value.

from jest-native.

brunohkbx avatar brunohkbx commented on June 8, 2024

I'll try to spare some time to help you guys. Do you have any suggestions in mind to fix that? If so, feel free to open a PR.

from jest-native.

thymikee avatar thymikee commented on June 8, 2024

@mdjastrzebski anything changing from RNTL side provided this PR you recently contributed? callstack/react-native-testing-library#460

from jest-native.

mdjastrzebski avatar mdjastrzebski commented on June 8, 2024

I'll try to reproduce it with TL/RN v7.

from jest-native.

yonatan-altaraz avatar yonatan-altaraz commented on June 8, 2024

i'm experiencing this too.
using these versions:

"@testing-library/jest-native": "^3.3.0",
"@testing-library/react-native": "^7.0.2",
"react-test-renderer": "16.6.3"

i see there's a flag called isAllowed in this function (toHaveProp), if it's false, the value check is ignored and it passes if the prop exists.
it seems to be false if the element is not in a 'valid_elements' list (don't understand why it's necessary), the issue in my case is:
this is the row to determine the flag value:
var isAllowed = _utils.VALID_ELEMENTS.includes(element.type); -> to-have-prop.js : 27
but VALID_ELEMENTS is a list of strings (components names) and element.type is a component instance, with a property displayName that suits this list. if i change your code to:
var isAllowed = _utils.VALID_ELEMENTS.includes(element.type.displayName);, is works fine.

also maybe i miss something but i don't understand why there are components that aren't allowed to have their props checked for values? (what is the meaning of that flag?)

from jest-native.

yonatan-altaraz avatar yonatan-altaraz commented on June 8, 2024

i now see it happens for me when i get the ReactTestInstance using getByText accessor,
and if i'm using getByTestId it returns a ReactTestInstance with a slightly different structure, with type property as string, and in this case toHaveProps works great.
maybe it's possible to add a check for the type of type property in the TestInstance?

from jest-native.

brunohkbx avatar brunohkbx commented on June 8, 2024

This one should be resolved by #36

from jest-native.

GoktuqCan avatar GoktuqCan commented on June 8, 2024

Still having this issue with version 3.4.3 and TouchableOpacity.
expect(getByTestId('test_id_test')).toHaveProp('disabled')

from jest-native.

shoonne avatar shoonne commented on June 8, 2024

Anyone having a solution to this? A test just randomly start failing which uses toHaveProp

from jest-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.